File tree Expand file tree Collapse file tree 4 files changed +49
-0
lines changed
tests/Elasticsearch/Tests Expand file tree Collapse file tree 4 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -7,3 +7,6 @@ parameters:
7
7
# because of \Elasticsearch\Tests\RegisteredNamespaceTest
8
8
- '#Call to an undefined method Elasticsearch\\Client::foo\ (\)#'
9
9
- '#Call to an undefined method Elasticsearch\\Client::bar\ (\)#'
10
+
11
+ # because of \Elasticsearch\Tests\ClientBuilderTest
12
+ - ' #expects Psr\\Log\\LoggerInterface , Elasticsearch\\Tests\\ClientBuilder\\DummyLogger given.$ #'
Original file line number Diff line number Diff line change @@ -307,6 +307,10 @@ public function setHandler($handler)
307
307
*/
308
308
public function setLogger ($ logger )
309
309
{
310
+ if (!$ logger instanceof LoggerInterface) {
311
+ throw new InvalidArgumentException ('$logger must implement \Psr\Log\LoggerInterface! ' );
312
+ }
313
+
310
314
$ this ->logger = $ logger ;
311
315
312
316
return $ this ;
@@ -318,6 +322,10 @@ public function setLogger($logger)
318
322
*/
319
323
public function setTracer ($ tracer )
320
324
{
325
+ if (!$ tracer instanceof LoggerInterface) {
326
+ throw new InvalidArgumentException ('$tracer must implement \Psr\Log\LoggerInterface! ' );
327
+ }
328
+
321
329
$ this ->tracer = $ tracer ;
322
330
323
331
return $ this ;
Original file line number Diff line number Diff line change
1
+ <?php
2
+ declare (strict_types = 1 );
3
+
4
+ namespace Elasticsearch \Tests \ClientBuilder ;
5
+
6
+ class DummyLogger
7
+ {
8
+
9
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types = 1 );
4
+
5
+ namespace Elasticsearch \Tests ;
6
+
7
+ use Elasticsearch \ClientBuilder ;
8
+ use Elasticsearch \Common \Exceptions \InvalidArgumentException ;
9
+ use PHPUnit \Framework \TestCase ;
10
+
11
+ class ClientBuilderTest extends TestCase
12
+ {
13
+
14
+ public function testClientBuilderThrowsExceptionForIncorrectLoggerClass ()
15
+ {
16
+ $ this ->expectException (InvalidArgumentException::class);
17
+ $ this ->expectExceptionMessage ('$logger must implement \Psr\Log\LoggerInterface! ' );
18
+
19
+ ClientBuilder::create ()->setLogger (new \Elasticsearch \Tests \ClientBuilder \DummyLogger ());
20
+ }
21
+
22
+ public function testClientBuilderThrowsExceptionForIncorrectTracerClass ()
23
+ {
24
+ $ this ->expectException (InvalidArgumentException::class);
25
+ $ this ->expectExceptionMessage ('$tracer must implement \Psr\Log\LoggerInterface! ' );
26
+
27
+ ClientBuilder::create ()->setTracer (new \Elasticsearch \Tests \ClientBuilder \DummyLogger ());
28
+ }
29
+ }
You can’t perform that action at this time.
0 commit comments