|
2 | 2 |
|
3 | 3 | namespace Hedii\LaravelGelfLogger\Tests\Processors; |
4 | 4 |
|
| 5 | +use DateTimeImmutable; |
5 | 6 | use Hedii\LaravelGelfLogger\Processors\RenameIdFieldProcessor; |
| 7 | +use Monolog\Level; |
| 8 | +use Monolog\LogRecord; |
6 | 9 | use PHPUnit\Framework\TestCase; |
7 | 10 |
|
8 | 11 | class RenameIdFieldProcessorTest extends TestCase |
9 | 12 | { |
10 | | - /** @test */ |
11 | | - public function it_should_rename_id_field(): void |
| 13 | + /** |
| 14 | + * @test |
| 15 | + * @dataProvider dataProvider |
| 16 | + */ |
| 17 | + public function it_should_rename_id_field(array $payloadContext, array $expected): void |
12 | 18 | { |
13 | | - $payload = [ |
14 | | - 'context' => ['id' => 'bar'], |
15 | | - ]; |
| 19 | + $payload = new LogRecord( |
| 20 | + datetime: new DateTimeImmutable(), |
| 21 | + channel: 'gelf', |
| 22 | + level: Level::Debug, |
| 23 | + message: 'message', |
| 24 | + context: $payloadContext |
| 25 | + ); |
16 | 26 |
|
17 | 27 | $processor = new RenameIdFieldProcessor(); |
18 | 28 |
|
19 | | - $this->assertSame(['context' => ['_id' => 'bar']], $processor($payload)); |
| 29 | + $this->assertSame($expected, $processor($payload)->context); |
| 30 | + } |
| 31 | + |
| 32 | + public static function dataProvider(): array |
| 33 | + { |
| 34 | + return [ |
| 35 | + 'having neither underscore id nor id' => [ |
| 36 | + ['someotherfield' => 'someothervalue'], |
| 37 | + ['someotherfield' => 'someothervalue'], |
| 38 | + ], |
| 39 | + 'having id and underscore id' => [ |
| 40 | + ['id' => 'bar', '_id' => 'bar2'], |
| 41 | + ['_id' => 'bar'], |
| 42 | + ], |
| 43 | + 'having id and not underscore id' => [ |
| 44 | + ['id' => 'bar'], |
| 45 | + ['_id' => 'bar'], |
| 46 | + ], |
| 47 | + 'having no id and underscore id' => [ |
| 48 | + ['_id' => 'bar', 'field1' => 'value1'], |
| 49 | + ['_id' => 'bar', 'field1' => 'value1'], |
| 50 | + ], |
| 51 | + ]; |
20 | 52 | } |
21 | 53 | } |
0 commit comments