ElasticClientFactoryTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 24
c 1
b 0
f 0
dl 0
loc 57
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 3 1
A createElasticClientFactory() 0 7 1
A testSimpleCreateClient() 0 9 1
A dataProvider() 0 17 1
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;
0 ignored issues
show
introduced by
The private property $applicationConfiguration is not used, and could be removed.
Loading history...
28
    private ElasticPluginConfigurationInterface $pluginConfiguration;
0 ignored issues
show
introduced by
The private property $pluginConfiguration is not used, and could be removed.
Loading history...
29
30
    private LoggerFacadeInterface $loggerFacade;
31
32
    private ElasticClientFactory $clientFactory;
0 ignored issues
show
introduced by
The private property $clientFactory is not used, and could be removed.
Loading history...
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);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($result) looks like debug code. Are you sure you do not want to remove it?
Loading history...
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