Skip to content

Commit 3edebac

Browse files
author
yangchenzhuo
committed
tests: add test unit
1 parent b1020a1 commit 3edebac

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/Transport/Adapter/Guzzle.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ public function setConfig(ClientInterface $client, array $config, array $clientO
4040
}
4141
}
4242
/** @var Client $client */
43-
$clientOptions = array_merge($clientOptions, $client->getConfig());
43+
if(method_exists($client, 'getConfig')){
44+
$clientOptions = array_merge($clientOptions, $client->getConfig());
45+
}
46+
4447
$class = get_class($client);
4548

4649
return new $class(array_merge($clientOptions, $guzzleConfig));

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)