1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Micro framework package. |
7
|
|
|
* |
8
|
|
|
* (c) Stanislau Komar <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Micro\Plugin\Elastic\Test\Unit\Configuration\Client; |
15
|
|
|
|
16
|
|
|
use Micro\Framework\Kernel\Configuration\DefaultApplicationConfiguration; |
17
|
|
|
use Micro\Plugin\Elastic\Configuration\Client\ElasticClientConfigurationInterface; |
18
|
|
|
use Micro\Plugin\Elastic\ElasticPluginConfiguration; |
19
|
|
|
use PHPUnit\Framework\TestCase; |
20
|
|
|
|
21
|
|
|
class ElasticClientConfigurationTest extends TestCase |
22
|
|
|
{ |
23
|
|
|
public function testDefaults(): void |
24
|
|
|
{ |
25
|
|
|
$clientCfg = $this->createConfiguration([]); |
26
|
|
|
|
27
|
|
|
$this->assertTrue($clientCfg->getRetries() > -1); |
28
|
|
|
$this->assertEquals('default', $clientCfg->getLoggerName()); |
29
|
|
|
$this->assertNull($clientCfg->getApiKey()); |
30
|
|
|
$this->assertNull($clientCfg->getCABundle()); |
31
|
|
|
$this->assertEquals('', $clientCfg->getBasicAuthLogin()); |
32
|
|
|
$this->assertEquals('', $clientCfg->getBasicAuthPassword()); |
33
|
|
|
$this->assertEquals(['localhost:9200'], $clientCfg->getHosts()); |
34
|
|
|
$this->assertNull($clientCfg->getElasticCloudId()); |
35
|
|
|
$this->assertNull($clientCfg->getSslKey()); |
36
|
|
|
$this->assertNull($clientCfg->getSslKeyPassword()); |
37
|
|
|
$this->assertTrue($clientCfg->getSslVerification()); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testOverride(): void |
41
|
|
|
{ |
42
|
|
|
$clientCfg = $this->createConfiguration([ |
43
|
|
|
'APP_ENV' => 'dev-test', |
44
|
|
|
'MICRO_ELASTIC_TEST_HOSTS' => 'test1,test2', |
45
|
|
|
'MICRO_ELASTIC_TEST_LOGGER' => 'test-logger', |
46
|
|
|
'MICRO_ELASTIC_TEST_RETRIES' => 2, |
47
|
|
|
'MICRO_ELASTIC_TEST_SSL_VERIFY' => false, |
48
|
|
|
'MICRO_ELASTIC_TEST_SSL_KEY' => 'test-key', |
49
|
|
|
'MICRO_ELASTIC_TEST_SSL_KEY_PASSWORD' => 'test-ssl-passwd', |
50
|
|
|
'MICRO_ELASTIC_TEST_API_KEY' => 'test-api-key', |
51
|
|
|
'MICRO_ELASTIC_TEST_AUTH_BASIC_LOGIN' => 'test-login', |
52
|
|
|
'MICRO_ELASTIC_TEST_AUTH_BASIC_PASSWORD' => 'test-password', |
53
|
|
|
'MICRO_ELASTIC_TEST_CLOUD_ID' => 'test-cloud-id', |
54
|
|
|
'MICRO_ELASTIC_TEST_CA_BUNDLE' => 'test-ca-bundle', |
55
|
|
|
]); |
56
|
|
|
|
57
|
|
|
$this->assertEquals(2, $clientCfg->getRetries()); |
58
|
|
|
$this->assertEquals('test-logger', $clientCfg->getLoggerName()); |
59
|
|
|
$this->assertEquals('test-api-key', $clientCfg->getApiKey()); |
60
|
|
|
$this->assertEquals('test-ca-bundle', $clientCfg->getCABundle()); |
61
|
|
|
$this->assertEquals('test-login', $clientCfg->getBasicAuthLogin()); |
62
|
|
|
$this->assertEquals('test-password', $clientCfg->getBasicAuthPassword()); |
63
|
|
|
$this->assertEquals(['test1', 'test2'], $clientCfg->getHosts()); |
64
|
|
|
$this->assertEquals('test-cloud-id', $clientCfg->getElasticCloudId()); |
65
|
|
|
$this->assertEquals('test-key', $clientCfg->getSslKey()); |
66
|
|
|
$this->assertEquals('test-ssl-passwd', $clientCfg->getSslKeyPassword()); |
67
|
|
|
$this->assertFalse($clientCfg->getSslVerification()); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
protected function createConfiguration(array $config): ElasticClientConfigurationInterface |
71
|
|
|
{ |
72
|
|
|
$appCfg = new DefaultApplicationConfiguration($config); |
73
|
|
|
$pluginConfiguration = new ElasticPluginConfiguration($appCfg); |
74
|
|
|
|
75
|
|
|
return $pluginConfiguration->getClientConfiguration('test'); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|