Issues (3641)

Business/Storage/StorageInstanceBuilderTest.php (1 issue)

1
<?php
2
3
/**
4
 * Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerTest\Zed\Collector\Business\Storage;
9
10
use Codeception\Test\Unit;
11
use ReflectionClass;
12
use Spryker\Zed\Collector\Business\Storage\StorageInstanceBuilder;
13
use Spryker\Zed\Collector\CollectorConfig;
14
use SprykerTest\Zed\Collector\CollectorBusinessTester;
15
16
/**
17
 * Auto-generated group annotations
18
 *
19
 * @group SprykerTest
20
 * @group Zed
21
 * @group Collector
22
 * @group Business
23
 * @group Storage
24
 * @group StorageInstanceBuilderTest
25
 * Add your own group annotations below this line
26
 */
27
class StorageInstanceBuilderTest extends Unit
28
{
29
    /**
30
     * @uses \Spryker\Shared\Search\SearchConstants::ELASTICA_PARAMETER__TRANSPORT
31
     *
32
     * @var string
33
     */
34
    protected const SEARCH_PARAMETER_TRANSPORT = 'ELASTICA_PARAMETER__TRANSPORT';
35
36
    /**
37
     * @uses \Spryker\Shared\Search\SearchConstants::ELASTICA_PARAMETER__PORT
38
     *
39
     * @var string
40
     */
41
    protected const SEARCH_PARAMETER_PORT = 'ELASTICA_PARAMETER__PORT';
42
43
    /**
44
     * @uses \Spryker\Shared\Search\SearchConstants::ELASTICA_PARAMETER__HOST
45
     *
46
     * @var string
47
     */
48
    protected const SEARCH_PARAMETER_HOST = 'ELASTICA_PARAMETER__HOST';
49
50
    /**
51
     * @var string
52
     */
53
    protected const ELASTICSEARCH_INSTANCE_CONFIG_KEY_TRANSPORT = 'transport';
54
55
    /**
56
     * @var string
57
     */
58
    protected const ELASTICSEARCH_INSTANCE_CONFIG_KEY_PORT = 'port';
59
60
    /**
61
     * @var string
62
     */
63
    protected const ELASTICSEARCH_INSTANCE_CONFIG_KEY_HOST = 'host';
64
65
    /**
66
     * @var \SprykerTest\Zed\Collector\CollectorBusinessTester
67
     */
68
    protected CollectorBusinessTester $tester;
69
70
    /**
71
     * @dataProvider getElasticsearchInstanceDataProvider
72
     *
73
     * @param list<string|null> $searchElasticsearchConfiguration
74
     * @param list<string|null> $searchConfiguration
75
     * @param list<string> $expectedInstanceConfiguration
76
     *
77
     * @return void
78
     */
79
    public function testGetElasticsearchInstance(
80
        array $searchElasticsearchConfiguration,
81
        array $searchConfiguration,
82
        array $expectedInstanceConfiguration
83
    ): void {
84
        // Arrange
85
        [$transport, $port, $host] = $searchElasticsearchConfiguration;
86
        $this->tester->mockEnvironmentConfig(CollectorConfig::SEARCH_ELASTICSEARCH_PARAMETER_TRANSPORT, $transport);
87
        $this->tester->mockEnvironmentConfig(CollectorConfig::SEARCH_ELASTICSEARCH_PARAMETER_PORT, $port);
88
        $this->tester->mockEnvironmentConfig(CollectorConfig::SEARCH_ELASTICSEARCH_PARAMETER_HOST, $host);
89
90
        [$transport, $port, $host] = $searchConfiguration;
91
        $this->tester->mockEnvironmentConfig(static::SEARCH_PARAMETER_TRANSPORT, $transport);
92
        $this->tester->mockEnvironmentConfig(static::SEARCH_PARAMETER_PORT, $port);
93
        $this->tester->mockEnvironmentConfig(static::SEARCH_PARAMETER_HOST, $host);
94
95
        [$transport, $port, $host] = $expectedInstanceConfiguration;
96
97
        $searchInstances = (new ReflectionClass(new StorageInstanceBuilder()))->getProperty('searchInstances');
98
        $searchInstances->setAccessible(true);
99
        $searchInstances->setValue([]);
100
        $searchInstances->setAccessible(false);
101
102
        // Act
103
        $elasticsearchInstanceConfig = StorageInstanceBuilder::getElasticsearchInstance()->getConfig();
104
105
        // Assert
106
        $this->assertSame($transport, $elasticsearchInstanceConfig[static::ELASTICSEARCH_INSTANCE_CONFIG_KEY_TRANSPORT]);
107
        $this->assertSame($port, $elasticsearchInstanceConfig[static::ELASTICSEARCH_INSTANCE_CONFIG_KEY_PORT]);
108
        $this->assertSame($host, $elasticsearchInstanceConfig[static::ELASTICSEARCH_INSTANCE_CONFIG_KEY_HOST]);
109
    }
110
111
    /**
112
     * @return array<array<list<string|null>>>
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<array<list<string|null>>> at position 4 could not be parsed: Expected '>' at position 4, but found 'list'.
Loading history...
113
     */
114
    protected function getElasticsearchInstanceDataProvider(): array
115
    {
116
        return [
117
            [
118
                [null, null, null], ['http', '777', 'remote'], ['Http', '777', 'remote'],
119
            ],
120
            [
121
                ['https', '999', 'localhost'], ['http', '777', 'remote'], ['Https', '999', 'localhost'],
122
            ],
123
            [
124
                ['https', '999', 'localhost'], [null, null, null], ['Https', '999', 'localhost'],
125
            ],
126
        ];
127
    }
128
}
129