providePlaceholderRecords()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

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