Completed
Push — master ( 5f85c6...f18f8c )
by Alejandro
13:24
created

properlyReplacesExceptionPlaceholderAddingNewLine()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace ShlinkioTest\Shlink\Common\Logger\Processor;
5
6
use PHPUnit\Framework\TestCase;
7
use Shlinkio\Shlink\Common\Logger\Processor\ExceptionWithNewLineProcessor;
8
use const PHP_EOL;
9
10
class ExceptionWithNewLineProcessorTest extends TestCase
11
{
12
    /**
13
     * @var ExceptionWithNewLineProcessor
14
     */
15
    private $processor;
16
17
    public function setUp()
18
    {
19
        $this->processor = new ExceptionWithNewLineProcessor();
20
    }
21
22
    /**
23
     * @test
24
     * @dataProvider provideNoPlaceholderRecords
25
     */
26
    public function keepsRecordAsIsWhenNoPlaceholderExists(array $record)
27
    {
28
        $this->assertSame($record, ($this->processor)($record));
29
    }
30
31
    public function provideNoPlaceholderRecords(): array
32
    {
33
        return [
34
            [['message' => 'Hello World']],
35
            [['message' => 'Shlink']],
36
            [['message' => 'Foo bar']],
37
        ];
38
    }
39
40
    /**
41
     * @test
42
     * @dataProvider providePlaceholderRecords
43
     */
44
    public function properlyReplacesExceptionPlaceholderAddingNewLine(array $record, array $expected)
45
    {
46
        $this->assertEquals($expected, ($this->processor)($record));
47
    }
48
49
    public function providePlaceholderRecords(): array
50
    {
51
        return [
52
            [
53
                ['message' => 'Hello World with placeholder {e}'],
54
                ['message' => 'Hello World with placeholder ' . PHP_EOL . '{e}'],
55
            ],
56
            [
57
                ['message' => '{e} Shlink'],
58
                ['message' => PHP_EOL . '{e} Shlink'],
59
            ],
60
            [
61
                ['message' => 'Foo {e} bar'],
62
                ['message' => 'Foo ' . PHP_EOL . '{e} bar'],
63
            ],
64
        ];
65
    }
66
}
67