15
15
use Magento \MagentoCloud \Config \Validator \Result \Success ;
16
16
use Magento \MagentoCloud \Config \Validator \ResultFactory ;
17
17
use Magento \MagentoCloud \Service \ElasticSearch ;
18
+ use Magento \MagentoCloud \Service \OpenSearch ;
18
19
use PHPUnit \Framework \MockObject \MockObject ;
19
20
use PHPUnit \Framework \TestCase ;
20
21
@@ -38,6 +39,11 @@ class ElasticSuiteIntegrityTest extends TestCase
38
39
*/
39
40
private $ elasticSearchMock ;
40
41
42
+ /**
43
+ * @var OpenSearch|MockObject
44
+ */
45
+ private $ openSearchMock ;
46
+
41
47
/**
42
48
* @var ResultFactory|MockObject
43
49
*/
@@ -55,12 +61,14 @@ protected function setUp(): void
55
61
{
56
62
$ this ->elasticSuiteMock = $ this ->createMock (ElasticSuite::class);
57
63
$ this ->elasticSearchMock = $ this ->createMock (ElasticSearch::class);
64
+ $ this ->openSearchMock = $ this ->createMock (OpenSearch::class);
58
65
$ this ->resultFactoryMock = $ this ->createMock (ResultFactory::class);
59
66
$ this ->stageConfigMock = $ this ->createMock (DeployInterface::class);
60
67
61
68
$ this ->validator = new ElasticSuiteIntegrity (
62
69
$ this ->elasticSuiteMock ,
63
70
$ this ->elasticSearchMock ,
71
+ $ this ->openSearchMock ,
64
72
$ this ->resultFactoryMock ,
65
73
$ this ->stageConfigMock
66
74
);
@@ -71,25 +79,82 @@ public function testValidate()
71
79
$ this ->elasticSuiteMock ->expects ($ this ->once ())
72
80
->method ('isInstalled ' )
73
81
->willReturn (false );
82
+ $ this ->elasticSearchMock ->expects ($ this ->never ())
83
+ ->method ('isInstalled ' );
84
+ $ this ->openSearchMock ->expects ($ this ->never ())
85
+ ->method ('isInstalled ' );
86
+ $ this ->resultFactoryMock ->expects ($ this ->once ())
87
+ ->method ('success ' )
88
+ ->willReturn (new Success ());
89
+
90
+ $ this ->assertInstanceOf (Success::class, $ this ->validator ->validate ());
91
+ }
92
+
93
+ public function testValidateEsOs ()
94
+ {
95
+ $ this ->elasticSuiteMock ->expects ($ this ->once ())
96
+ ->method ('isInstalled ' )
97
+ ->willReturn (true );
98
+ $ this ->openSearchMock ->expects ($ this ->once ())
99
+ ->method ('isInstalled ' )
100
+ ->willReturn (true );
101
+ $ this ->resultFactoryMock ->expects ($ this ->once ())
102
+ ->method ('success ' )
103
+ ->willReturn (new Success ());
104
+
105
+ $ this ->assertInstanceOf (Success::class, $ this ->validator ->validate ());
106
+ }
107
+
108
+ public function testValidateEs ()
109
+ {
110
+ $ this ->elasticSuiteMock ->expects ($ this ->once ())
111
+ ->method ('isInstalled ' )
112
+ ->willReturn (true );
113
+ $ this ->elasticSearchMock ->expects ($ this ->once ())
114
+ ->method ('isInstalled ' )
115
+ ->willReturn (true );
116
+ $ this ->openSearchMock ->expects ($ this ->never ())
117
+ ->method ('isInstalled ' );
118
+ $ this ->resultFactoryMock ->expects ($ this ->once ())
119
+ ->method ('success ' )
120
+ ->willReturn (new Success ());
121
+
122
+ $ this ->assertInstanceOf (Success::class, $ this ->validator ->validate ());
123
+ }
124
+
125
+ public function testValidateOs ()
126
+ {
127
+ $ this ->elasticSuiteMock ->expects ($ this ->once ())
128
+ ->method ('isInstalled ' )
129
+ ->willReturn (true );
130
+ $ this ->elasticSearchMock ->expects ($ this ->once ())
131
+ ->method ('isInstalled ' )
132
+ ->willReturn (false );
133
+ $ this ->openSearchMock ->expects ($ this ->once ())
134
+ ->method ('isInstalled ' )
135
+ ->willReturn (true );
74
136
$ this ->resultFactoryMock ->expects ($ this ->once ())
75
137
->method ('success ' )
76
138
->willReturn (new Success ());
77
139
78
140
$ this ->assertInstanceOf (Success::class, $ this ->validator ->validate ());
79
141
}
80
142
81
- public function testValidateNoESInstalled ()
143
+ public function testValidateNoESandOSInstalled ()
82
144
{
83
145
$ this ->elasticSuiteMock ->expects ($ this ->once ())
84
146
->method ('isInstalled ' )
85
147
->willReturn (true );
86
148
$ this ->elasticSearchMock ->expects ($ this ->once ())
87
149
->method ('isInstalled ' )
88
150
->willReturn (false );
151
+ $ this ->openSearchMock ->expects ($ this ->once ())
152
+ ->method ('isInstalled ' )
153
+ ->willReturn (false );
89
154
$ this ->resultFactoryMock ->expects ($ this ->once ())
90
155
->method ('error ' )
91
156
->with (
92
- 'ElasticSuite is installed without available ElasticSearch service. ' ,
157
+ 'ElasticSuite is installed without available ElasticSearch or OpenSearch service. ' ,
93
158
'' ,
94
159
AppError::DEPLOY_ELASTIC_SUITE_WITHOUT_ES
95
160
)
@@ -106,6 +171,8 @@ public function testValidateSearchEngineIsMysql()
106
171
$ this ->elasticSearchMock ->expects ($ this ->once ())
107
172
->method ('isInstalled ' )
108
173
->willReturn (true );
174
+ $ this ->openSearchMock ->expects ($ this ->never ())
175
+ ->method ('isInstalled ' );
109
176
$ this ->stageConfigMock ->expects ($ this ->once ())
110
177
->method ('get ' )
111
178
->with (DeployInterface::VAR_SEARCH_CONFIGURATION )
@@ -130,6 +197,8 @@ public function testValidateNoErrors()
130
197
$ this ->elasticSearchMock ->expects ($ this ->once ())
131
198
->method ('isInstalled ' )
132
199
->willReturn (true );
200
+ $ this ->openSearchMock ->expects ($ this ->never ())
201
+ ->method ('isInstalled ' );
133
202
$ this ->stageConfigMock ->expects ($ this ->once ())
134
203
->method ('get ' )
135
204
->with (DeployInterface::VAR_SEARCH_CONFIGURATION )
0 commit comments