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\Client\Factory; |
15
|
|
|
|
16
|
|
|
use Micro\Framework\Kernel\Configuration\ApplicationConfigurationInterface; |
17
|
|
|
use Micro\Framework\Kernel\Configuration\DefaultApplicationConfiguration; |
18
|
|
|
use Micro\Plugin\Elastic\Client\Factory\ElasticClientFactory; |
19
|
|
|
use Micro\Plugin\Elastic\Client\Factory\ElasticClientFactoryInterface; |
20
|
|
|
use Micro\Plugin\Elastic\Configuration\ElasticPluginConfigurationInterface; |
21
|
|
|
use Micro\Plugin\Elastic\ElasticPluginConfiguration; |
22
|
|
|
use Micro\Plugin\Logger\Facade\LoggerFacadeInterface; |
23
|
|
|
use PHPUnit\Framework\TestCase; |
24
|
|
|
|
25
|
|
|
class ElasticClientFactoryTest extends TestCase |
26
|
|
|
{ |
27
|
|
|
private ApplicationConfigurationInterface $applicationConfiguration; |
|
|
|
|
28
|
|
|
private ElasticPluginConfigurationInterface $pluginConfiguration; |
|
|
|
|
29
|
|
|
|
30
|
|
|
private LoggerFacadeInterface $loggerFacade; |
31
|
|
|
|
32
|
|
|
private ElasticClientFactory $clientFactory; |
|
|
|
|
33
|
|
|
|
34
|
|
|
protected function setUp(): void |
35
|
|
|
{ |
36
|
|
|
$this->loggerFacade = $this->createMock(LoggerFacadeInterface::class); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @dataProvider dataProvider |
41
|
|
|
*/ |
42
|
|
|
public function testSimpleCreateClient(array $configuration): void |
43
|
|
|
{ |
44
|
|
|
$factory = $this->createElasticClientFactory($configuration); |
45
|
|
|
|
46
|
|
|
$result = $factory->create('test'); |
47
|
|
|
|
48
|
|
|
var_dump($result); |
|
|
|
|
49
|
|
|
|
50
|
|
|
$this->assertTrue(true); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function dataProvider(): array |
54
|
|
|
{ |
55
|
|
|
return [ |
56
|
|
|
[ |
57
|
|
|
[ |
58
|
|
|
'APP_ENV' => 'dev-test', |
59
|
|
|
'MICRO_ELASTIC_TEST_HOSTS' => 'localhost', |
60
|
|
|
'MICRO_ELASTIC_TEST_LOGGER' => 'default', |
61
|
|
|
'MICRO_ELASTIC_TEST_RETRIES' => 2, |
62
|
|
|
'MICRO_ELASTIC_TEST_SSL_VERIFY' => true, |
63
|
|
|
'MICRO_ELASTIC_TEST_SSL_KEY' => 'test-key', |
64
|
|
|
'MICRO_ELASTIC_TEST_SSL_KEY_PASSWORD' => 'test-passwd', |
65
|
|
|
// 'MICRO_ELASTIC_TEST_API_KEY' => 'test-api-key', |
66
|
|
|
'MICRO_ELASTIC_TEST_AUTH_BASIC_LOGIN' => 'test-login', |
67
|
|
|
'MICRO_ELASTIC_TEST_AUTH_BASIC_PASSWORD' => 'test-password', |
68
|
|
|
// 'MICRO_ELASTIC_TEST_CLOUD_ID' => 'test-cloud-id', |
69
|
|
|
'MICRO_ELASTIC_TEST_CA_BUNDLE' => 'test-ca-bundle', |
70
|
|
|
], |
71
|
|
|
], |
72
|
|
|
]; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
protected function createElasticClientFactory(array $configuration): ElasticClientFactoryInterface |
76
|
|
|
{ |
77
|
|
|
$appConfig = new DefaultApplicationConfiguration($configuration); |
78
|
|
|
|
79
|
|
|
$pluginConfig = new ElasticPluginConfiguration($appConfig); |
80
|
|
|
|
81
|
|
|
return new ElasticClientFactory($pluginConfig, $this->loggerFacade); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|