-
Notifications
You must be signed in to change notification settings - Fork 972
Expand file tree
/
Copy pathGuzzleTest.php
More file actions
76 lines (66 loc) · 2.79 KB
/
GuzzleTest.php
File metadata and controls
76 lines (66 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
/**
* Elasticsearch PHP Client
*
* @link https://github.com/elastic/elasticsearch-php
* @copyright Copyright (c) Elasticsearch B.V (https://www.elastic.co)
* @license https://opensource.org/licenses/MIT MIT License
*
* Licensed to Elasticsearch B.V under one or more agreements.
* Elasticsearch B.V licenses this file to you under the MIT License.
* See the LICENSE file in the project root for more information.
*/
declare(strict_types = 1);
namespace Elastic\Elasticsearch\Tests\Transport\Adapter;
use Elastic\Elasticsearch\Transport\Adapter\Guzzle;
use Elastic\Elasticsearch\Transport\RequestOptions;
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\RequestOptions As GuzzleOptions;
use PHPUnit\Framework\TestCase;
use Psr\Http\Client\ClientInterface;
class GuzzleTest extends TestCase
{
protected Guzzle $guzzleAdapter;
protected ClientInterface $client;
public function setUp(): void
{
$this->guzzleAdapter = new Guzzle;
$this->client = $this->createStub(ClientInterface::class);
}
public function testSetConfigWithEmptyArray()
{
$result = $this->guzzleAdapter->setConfig($this->client, [], []);
$this->assertInstanceOf(ClientInterface::class, $result);
}
public function testSetConfigWithSslCert()
{
$result = $this->guzzleAdapter->setConfig(new Client(), [ RequestOptions::SSL_CERT => 'test'], []);
$this->assertInstanceOf(Client::class, $result);
$this->assertEquals('test', $result->getConfig(GuzzleOptions::CERT));
}
public function testSetConfigWithSslKey()
{
$result = $this->guzzleAdapter->setConfig(new Client(), [ RequestOptions::SSL_KEY => 'test'], []);
$this->assertInstanceOf(Client::class, $result);
$this->assertEquals('test', $result->getConfig(GuzzleOptions::SSL_KEY));
}
public function testSetConfigWithSslVerify()
{
$result = $this->guzzleAdapter->setConfig(new Client(), [ RequestOptions::SSL_VERIFY => false], []);
$this->assertInstanceOf(Client::class, $result);
$this->assertEquals(false, $result->getConfig(GuzzleOptions::VERIFY));
}
public function testSetConfigWithSslCa()
{
$result = $this->guzzleAdapter->setConfig(new Client(), [ RequestOptions::SSL_CA => 'test'], []);
$this->assertInstanceOf(Client::class, $result);
$this->assertEquals('test', $result->getConfig(GuzzleOptions::VERIFY));
}
public function testSetConfigButNotOverwrittenClientOptions()
{
$result = $this->guzzleAdapter->setConfig(new Client(['base_uri' => 'http://localhost:12345']), [ RequestOptions::SSL_CA => 'test'], []);
$this->assertInstanceOf(Client::class, $result);
$this->assertEquals('http://localhost:12345', $result->getConfig('base_uri'));
}
}