Skip to content

Commit 8e98d06

Browse files
author
minororange
committed
fix: Custom Guzzle/Client Configuration Has Been Overwritten
tests: add test unit
1 parent 2407a37 commit 8e98d06

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/Transport/Adapter/Guzzle.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
namespace Elastic\Elasticsearch\Transport\Adapter;
1616

1717
use Elastic\Elasticsearch\Transport\RequestOptions;
18+
use GuzzleHttp\Client;
1819
use GuzzleHttp\RequestOptions As GuzzleOptions;
1920
use Psr\Http\Client\ClientInterface;
2021

@@ -38,7 +39,13 @@ public function setConfig(ClientInterface $client, array $config, array $clientO
3839
$guzzleConfig[GuzzleOptions::VERIFY] = $value;
3940
}
4041
}
42+
/** @var Client $client */
43+
if(method_exists($client, 'getConfig')){
44+
$clientOptions = array_merge($clientOptions, $client->getConfig());
45+
}
46+
4147
$class = get_class($client);
48+
4249
return new $class(array_merge($clientOptions, $guzzleConfig));
4350
}
4451
}

tests/Transport/Adapter/GuzzleTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Elastic\Elasticsearch\Transport\Adapter\Guzzle;
1818
use Elastic\Elasticsearch\Transport\RequestOptions;
1919
use GuzzleHttp\Client;
20+
use GuzzleHttp\HandlerStack;
2021
use GuzzleHttp\RequestOptions As GuzzleOptions;
2122
use PHPUnit\Framework\TestCase;
2223
use Psr\Http\Client\ClientInterface;
@@ -65,4 +66,11 @@ public function testSetConfigWithSslCa()
6566
$this->assertInstanceOf(Client::class, $result);
6667
$this->assertEquals('test', $result->getConfig(GuzzleOptions::VERIFY));
6768
}
69+
70+
public function testSetConfigButNotOverwrittenClientOptions()
71+
{
72+
$result = $this->guzzleAdapter->setConfig(new Client(['base_uri' => 'http://localhost:12345']), [ RequestOptions::SSL_CA => 'test'], []);
73+
$this->assertInstanceOf(Client::class, $result);
74+
$this->assertEquals('http://localhost:12345', $result->getConfig('base_uri'));
75+
}
6876
}

0 commit comments

Comments
 (0)