Passed
Pull Request — master (#31)
by
unknown
13:33
created

LoggerBuilderIntegrationTest::tearDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Graze\Monolog;
4
5
use Mockery;
6
use Monolog\Logger;
7
use PHPUnit\Framework\TestCase;
8
9
class LoggerBuilderIntegrationTest extends TestCase
10
{
11
    /** @var LoggerBuilder */
12
    private $builder;
13
14
    public function setUp(): void
15
    {
16
        $this->builder = new LoggerBuilder();
17
    }
18
19
    public function tearDown(): void
20
    {
21
        parent::tearDown();
22
        Mockery::close();
23
    }
24
25
    /**
26
     * @param Logger $logger
27
     */
28
    public function assertDefaultHandlers(Logger $logger)
29
    {
30
        $handlers = [];
31
        $exception = null;
32
        do {
33
            try {
34
                $handlers[] = $handler = $logger->popHandler();
0 ignored issues
show
Unused Code introduced by
The assignment to $handler is dead and can be removed.
Loading history...
35
            } catch (\Exception $e) {
36
                $exception = $e;
37
            }
38
        } while (is_null($exception));
39
40
        $this->assertSame([], $handlers, 'There are more handlers defined than should be');
41
    }
42
43
    /**
44
     * @param Logger $logger
45
     */
46
    public function assertDefaultProcessors(Logger $logger)
47
    {
48
        $processors = [];
49
        $exception = null;
50
        do {
51
            try {
52
                $processors[] = $processor = $logger->popProcessor();
0 ignored issues
show
Unused Code introduced by
The assignment to $processor is dead and can be removed.
Loading history...
53
            } catch (\Exception $e) {
54
                $exception = $e;
55
            }
56
        } while (is_null($exception));
57
58
        $this->assertInstanceOf('Graze\Monolog\Processor\ExceptionMessageProcessor', array_shift($processors));
59
        $this->assertInstanceOf('Graze\Monolog\Processor\EnvironmentProcessor', array_shift($processors));
60
        $this->assertInstanceOf('Graze\Monolog\Processor\HttpProcessor', array_shift($processors));
61
        $this->assertSame([], $processors, 'There are more processors defined than should be');
62
    }
63
64
    public function testBuild()
65
    {
66
        $logger = $this->builder->build();
67
68
        $this->assertSame(LoggerBuilder::DEFAULT_NAME, $logger->getName());
69
        $this->assertDefaultHandlers($logger);
70
        $this->assertDefaultProcessors($logger);
71
    }
72
}
73