@@ -69,6 +69,8 @@ public function testProcess(): void
6969 $ containerBuilderProphecy = $ this ->prophesize (ContainerBuilder::class);
7070 $ containerBuilderProphecy ->getParameter ('api_platform.elasticsearch.enabled ' )->willReturn (true )->shouldBeCalled ();
7171 $ containerBuilderProphecy ->getParameter ('api_platform.elasticsearch.hosts ' )->willReturn (['http://localhost:9200 ' ])->shouldBeCalled ();
72+ $ containerBuilderProphecy ->getParameter ('api_platform.elasticsearch.ssl_ca_bundle ' )->willReturn (null )->shouldBeCalled ();
73+ $ containerBuilderProphecy ->getParameter ('api_platform.elasticsearch.ssl_verification ' )->willReturn (true )->shouldBeCalled ();
7274 $ containerBuilderProphecy ->has ('logger ' )->willReturn (true )->shouldBeCalled ();
7375 $ containerBuilderProphecy ->getDefinition ('api_platform.elasticsearch.client ' )->willReturn ($ clientDefinitionProphecy ->reveal ())->shouldBeCalled ();
7476
@@ -89,6 +91,8 @@ public function testProcessWithoutConfiguration(): void
8991 $ containerBuilderProphecy = $ this ->prophesize (ContainerBuilder::class);
9092 $ containerBuilderProphecy ->getParameter ('api_platform.elasticsearch.enabled ' )->willReturn (true )->shouldBeCalled ();
9193 $ containerBuilderProphecy ->getParameter ('api_platform.elasticsearch.hosts ' )->willReturn ([])->shouldBeCalled ();
94+ $ containerBuilderProphecy ->getParameter ('api_platform.elasticsearch.ssl_ca_bundle ' )->willReturn (null )->shouldBeCalled ();
95+ $ containerBuilderProphecy ->getParameter ('api_platform.elasticsearch.ssl_verification ' )->willReturn (true )->shouldBeCalled ();
9296 $ containerBuilderProphecy ->has ('logger ' )->willReturn (false )->shouldBeCalled ();
9397 $ containerBuilderProphecy ->getDefinition ('api_platform.elasticsearch.client ' )->willReturn ($ clientDefinitionProphecy ->reveal ())->shouldBeCalled ();
9498
@@ -102,4 +106,102 @@ public function testProcessWithElasticsearchDisabled(): void
102106
103107 (new ElasticsearchClientPass ())->process ($ containerBuilderProphecy ->reveal ());
104108 }
109+
110+ public function testProcessWithSslCaBundle (): void
111+ {
112+ $ clientBuilder = class_exists (\Elasticsearch \ClientBuilder::class)
113+ // ES v7
114+ ? \Elasticsearch \ClientBuilder::class
115+ // ES v8 and up
116+ : \Elastic \Elasticsearch \ClientBuilder::class;
117+
118+ $ clientDefinition = $ this ->createMock (Definition::class);
119+ $ clientDefinition ->expects ($ this ->once ())
120+ ->method ('setFactory ' )
121+ ->with ([$ clientBuilder , 'fromConfig ' ])
122+ ->willReturnSelf ();
123+
124+ $ clientDefinition ->expects ($ this ->once ())
125+ ->method ('setArguments ' )
126+ ->with ($ this ->callback (function ($ arguments ) {
127+ $ config = $ arguments [0 ];
128+
129+ return isset ($ config ['hosts ' ])
130+ && $ config ['hosts ' ] === ['https://localhost:9200 ' ]
131+ && isset ($ config ['CABundle ' ])
132+ && '/path/to/ca-bundle.crt ' === $ config ['CABundle ' ]
133+ && isset ($ config ['logger ' ])
134+ && $ config ['logger ' ] instanceof Reference;
135+ }))
136+ ->willReturnSelf ();
137+
138+ $ containerBuilder = $ this ->createMock (ContainerBuilder::class);
139+ $ containerBuilder ->method ('getParameter ' )
140+ ->willReturnMap ([
141+ ['api_platform.elasticsearch.enabled ' , true ],
142+ ['api_platform.elasticsearch.hosts ' , ['https://localhost:9200 ' ]],
143+ ['api_platform.elasticsearch.ssl_ca_bundle ' , '/path/to/ca-bundle.crt ' ],
144+ ['api_platform.elasticsearch.ssl_verification ' , true ],
145+ ]);
146+
147+ $ containerBuilder ->expects ($ this ->once ())
148+ ->method ('has ' )
149+ ->with ('logger ' )
150+ ->willReturn (true );
151+
152+ $ containerBuilder ->expects ($ this ->once ())
153+ ->method ('getDefinition ' )
154+ ->with ('api_platform.elasticsearch.client ' )
155+ ->willReturn ($ clientDefinition );
156+
157+ (new ElasticsearchClientPass ())->process ($ containerBuilder );
158+ }
159+
160+ public function testProcessWithSslVerificationDisabled (): void
161+ {
162+ $ clientBuilder = class_exists (\Elasticsearch \ClientBuilder::class)
163+ ? \Elasticsearch \ClientBuilder::class
164+ : \Elastic \Elasticsearch \ClientBuilder::class;
165+
166+ $ clientDefinition = $ this ->createMock (Definition::class);
167+ $ clientDefinition ->expects ($ this ->once ())
168+ ->method ('setFactory ' )
169+ ->with ([$ clientBuilder , 'fromConfig ' ])
170+ ->willReturnSelf ();
171+
172+ $ clientDefinition ->expects ($ this ->once ())
173+ ->method ('setArguments ' )
174+ ->with ($ this ->callback (function ($ arguments ) {
175+ $ config = $ arguments [0 ];
176+
177+ return isset ($ config ['hosts ' ])
178+ && $ config ['hosts ' ] === ['https://localhost:9200 ' ]
179+ && isset ($ config ['SSLVerification ' ])
180+ && false === $ config ['SSLVerification ' ]
181+ && isset ($ config ['logger ' ])
182+ && $ config ['logger ' ] instanceof Reference;
183+ }))
184+ ->willReturnSelf ();
185+
186+ $ containerBuilder = $ this ->createMock (ContainerBuilder::class);
187+ $ containerBuilder ->method ('getParameter ' )
188+ ->willReturnMap ([
189+ ['api_platform.elasticsearch.enabled ' , true ],
190+ ['api_platform.elasticsearch.hosts ' , ['https://localhost:9200 ' ]],
191+ ['api_platform.elasticsearch.ssl_ca_bundle ' , null ],
192+ ['api_platform.elasticsearch.ssl_verification ' , false ],
193+ ]);
194+
195+ $ containerBuilder ->expects ($ this ->once ())
196+ ->method ('has ' )
197+ ->with ('logger ' )
198+ ->willReturn (true );
199+
200+ $ containerBuilder ->expects ($ this ->once ())
201+ ->method ('getDefinition ' )
202+ ->with ('api_platform.elasticsearch.client ' )
203+ ->willReturn ($ clientDefinition );
204+
205+ (new ElasticsearchClientPass ())->process ($ containerBuilder );
206+ }
105207}
0 commit comments