Skip to content

Commit f22755b

Browse files
committed
Changed DummyLogger in favor of ArrayLogger
1 parent 98c336b commit f22755b

File tree

3 files changed

+67
-60
lines changed

3 files changed

+67
-60
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
declare(strict_types = 1);
3+
4+
namespace Elasticsearch\Tests\ClientBuilder;
5+
6+
use Psr\Log\LoggerInterface;
7+
use Psr\Log\LogLevel;
8+
9+
class ArrayLogger implements LoggerInterface
10+
{
11+
public $output = [];
12+
13+
public function emergency($message, array $context = array())
14+
{
15+
$this->log(LogLevel::EMERGENCY, $message, $context);
16+
}
17+
18+
public function alert($message, array $context = array())
19+
{
20+
$this->log(LogLevel::ALERT, $message, $context);
21+
}
22+
23+
public function critical($message, array $context = array())
24+
{
25+
$this->log(LogLevel::CRITICAL, $message, $context);
26+
}
27+
28+
public function error($message, array $context = array())
29+
{
30+
$this->log(LogLevel::ERROR, $message, $context);
31+
}
32+
33+
public function warning($message, array $context = array())
34+
{
35+
$this->log(LogLevel::WARNING, $message, $context);
36+
}
37+
38+
public function notice($message, array $context = array())
39+
{
40+
$this->log(LogLevel::NOTICE, $message, $context);
41+
}
42+
43+
public function info($message, array $context = array())
44+
{
45+
$this->log(LogLevel::INFO, $message, $context);
46+
}
47+
48+
public function debug($message, array $context = array())
49+
{
50+
$this->log(LogLevel::DEBUG, $message, $context);
51+
}
52+
53+
public function log($level, $message, array $context = array())
54+
{
55+
$this->output[] = sprintf("%s: %s %s", $level, $message, json_encode($context));
56+
}
57+
}

tests/Elasticsearch/Tests/ClientBuilder/DummyLogger.php

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,55 +3,7 @@
33

44
namespace Elasticsearch\Tests\ClientBuilder;
55

6-
use Psr\Log\LoggerInterface;
7-
use Psr\Log\LogLevel;
8-
9-
class DummyLogger implements LoggerInterface
6+
class DummyLogger
107
{
11-
public $output = [];
12-
13-
public function emergency($message, array $context = array())
14-
{
15-
$this->log(LogLevel::EMERGENCY, $message, $context);
16-
}
17-
18-
public function alert($message, array $context = array())
19-
{
20-
$this->log(LogLevel::ALERT, $message, $context);
21-
}
22-
23-
public function critical($message, array $context = array())
24-
{
25-
$this->log(LogLevel::CRITICAL, $message, $context);
26-
}
27-
28-
public function error($message, array $context = array())
29-
{
30-
$this->log(LogLevel::ERROR, $message, $context);
31-
}
32-
33-
public function warning($message, array $context = array())
34-
{
35-
$this->log(LogLevel::WARNING, $message, $context);
36-
}
37-
38-
public function notice($message, array $context = array())
39-
{
40-
$this->log(LogLevel::NOTICE, $message, $context);
41-
}
42-
43-
public function info($message, array $context = array())
44-
{
45-
$this->log(LogLevel::INFO, $message, $context);
46-
}
47-
48-
public function debug($message, array $context = array())
49-
{
50-
$this->log(LogLevel::DEBUG, $message, $context);
51-
}
52-
53-
public function log($level, $message, array $context = array())
54-
{
55-
$this->output[] = sprintf("%s: %s %s", $level, $message, json_encode($context));
56-
}
8+
579
}

tests/Elasticsearch/Tests/ClientIntegrationTests.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use Elasticsearch\ClientBuilder;
88
use Elasticsearch\Common\Exceptions\Missing404Exception;
9-
use Elasticsearch\Tests\ClientBuilder\DummyLogger;
9+
use Elasticsearch\Tests\ClientBuilder\ArrayLogger;
1010
use Psr\Log\LogLevel;
1111

1212
/**
@@ -26,40 +26,38 @@ public function setUp()
2626
if (empty(getenv('ES_TEST_HOST'))) {
2727
$this->markTestSkipped('I cannot execute integration test without ES_TEST_HOST env');
2828
}
29+
$this->logger = new ArrayLogger();
2930
}
3031

3132
public function testLogRequestSuccessHasInfoNotEmpty()
3233
{
33-
$logger = new DummyLogger();
3434
$client = ClientBuilder::create()
3535
->setHosts([getenv('ES_TEST_HOST')])
36-
->setLogger($logger)
36+
->setLogger($this->logger)
3737
->build();
3838

3939
$result = $client->info();
4040

41-
$this->assertNotEmpty($this->getLevelOutput(LogLevel::INFO, $logger->output));
41+
$this->assertNotEmpty($this->getLevelOutput(LogLevel::INFO, $this->logger->output));
4242
}
4343

4444
public function testLogRequestSuccessHasPortInInfo()
4545
{
46-
$logger = new DummyLogger();
4746
$client = ClientBuilder::create()
4847
->setHosts([getenv('ES_TEST_HOST')])
49-
->setLogger($logger)
48+
->setLogger($this->logger)
5049
->build();
5150

5251
$result = $client->info();
5352

54-
$this->assertContains('"port"', $this->getLevelOutput(LogLevel::INFO, $logger->output));
53+
$this->assertContains('"port"', $this->getLevelOutput(LogLevel::INFO, $this->logger->output));
5554
}
5655

5756
public function testLogRequestFailHasWarning()
5857
{
59-
$logger = new DummyLogger();
6058
$client = ClientBuilder::create()
6159
->setHosts([getenv('ES_TEST_HOST')])
62-
->setLogger($logger)
60+
->setLogger($this->logger)
6361
->build();
6462

6563
try {
@@ -68,7 +66,7 @@ public function testLogRequestFailHasWarning()
6866
'id' => 'bar'
6967
]);
7068
} catch (Missing404Exception $e) {
71-
$this->assertNotEmpty($this->getLevelOutput(LogLevel::WARNING, $logger->output));
69+
$this->assertNotEmpty($this->getLevelOutput(LogLevel::WARNING, $this->logger->output));
7270
}
7371
}
7472

0 commit comments

Comments
 (0)