1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace ArpTest\LaminasMonolog\Factory\Formatter; |
6
|
|
|
|
7
|
|
|
use Arp\LaminasFactory\FactoryInterface; |
8
|
|
|
use Arp\LaminasMonolog\Factory\Formatter\LineFormatterFactory; |
9
|
|
|
use Laminas\ServiceManager\Exception\ServiceNotCreatedException; |
10
|
|
|
use Monolog\Formatter\LineFormatter; |
11
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
12
|
|
|
use PHPUnit\Framework\TestCase; |
13
|
|
|
use Psr\Container\ContainerExceptionInterface; |
14
|
|
|
use Psr\Container\ContainerInterface; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @covers \Arp\LaminasMonolog\Factory\Formatter\LineFormatterFactory |
18
|
|
|
* @covers \Arp\LaminasMonolog\Factory\Formatter\AbstractNormalizerFormatterFactory |
19
|
|
|
*/ |
20
|
|
|
final class LineFormatterFactoryTest extends TestCase |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var ContainerInterface&MockObject |
24
|
|
|
*/ |
25
|
|
|
private ContainerInterface $container; |
26
|
|
|
|
27
|
|
|
public function setUp(): void |
28
|
|
|
{ |
29
|
|
|
$this->container = $this->createMock(ContainerInterface::class); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testImplementsFactoryInterface(): void |
33
|
|
|
{ |
34
|
|
|
$factory = new LineFormatterFactory(); |
35
|
|
|
|
36
|
|
|
$this->assertInstanceOf(FactoryInterface::class, $factory); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @dataProvider getInvokeWillReturnConfiguredLineFormatterInstanceData |
41
|
|
|
* |
42
|
|
|
* @param array<mixed> $options |
43
|
|
|
* |
44
|
|
|
* @throws ServiceNotCreatedException |
45
|
|
|
* @throws ContainerExceptionInterface |
46
|
|
|
*/ |
47
|
|
|
public function testInvokeWillReturnConfiguredLineFormatterInstance(array $options): void |
48
|
|
|
{ |
49
|
|
|
$factory = new LineFormatterFactory(); |
50
|
|
|
|
51
|
|
|
$formatter = $factory($this->container, LineFormatter::class, $options); |
52
|
|
|
|
53
|
|
|
if (isset($options['date_format'])) { |
54
|
|
|
$this->assertSame($options['date_format'], $formatter->getDateFormat()); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
if (isset($options['max_normalize_depth'])) { |
58
|
|
|
$this->assertSame($options['max_normalize_depth'], $formatter->getMaxNormalizeDepth()); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
$this->assertInstanceOf(LineFormatter::class, $formatter); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return array<mixed> |
66
|
|
|
*/ |
67
|
|
|
public function getInvokeWillReturnConfiguredLineFormatterInstanceData(): array |
68
|
|
|
{ |
69
|
|
|
return [ |
70
|
|
|
[ |
71
|
|
|
[], |
72
|
|
|
], |
73
|
|
|
[ |
74
|
|
|
[ |
75
|
|
|
'date_format' => 'Y-m-d H:i:s', |
76
|
|
|
], |
77
|
|
|
], |
78
|
|
|
[ |
79
|
|
|
[ |
80
|
|
|
'max_normalize_depth' => 100, |
81
|
|
|
], |
82
|
|
|
], |
83
|
|
|
[ |
84
|
|
|
[ |
85
|
|
|
'max_normalize_item_count' => 2000, |
86
|
|
|
'json_pretty_print' => true, |
87
|
|
|
'json_encode_options' => [ |
88
|
|
|
\JSON_THROW_ON_ERROR, |
89
|
|
|
] |
90
|
|
|
] |
91
|
|
|
], |
92
|
|
|
]; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|