|
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
|
|
|
|