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
|
|
|
* @author Alex Patterson <[email protected]> |
21
|
|
|
* @package ArpTest\LaminasMonolog\Factory\Formatter |
22
|
|
|
*/ |
23
|
|
|
final class LineFormatterFactoryTest extends TestCase |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var ContainerInterface&MockObject |
27
|
|
|
*/ |
28
|
|
|
private ContainerInterface $container; |
29
|
|
|
|
30
|
|
|
public function setUp(): void |
31
|
|
|
{ |
32
|
|
|
$this->container = $this->createMock(ContainerInterface::class); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testImplementsFactoryInterface(): void |
36
|
|
|
{ |
37
|
|
|
$factory = new LineFormatterFactory(); |
38
|
|
|
|
39
|
|
|
$this->assertInstanceOf(FactoryInterface::class, $factory); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @dataProvider getInvokeWillReturnConfiguredLineFormatterInstanceData |
44
|
|
|
* |
45
|
|
|
* @param array<mixed> $options |
46
|
|
|
* |
47
|
|
|
* @throws ServiceNotCreatedException |
48
|
|
|
* @throws ContainerExceptionInterface |
49
|
|
|
*/ |
50
|
|
|
public function testInvokeWillReturnConfiguredLineFormatterInstance(array $options): void |
51
|
|
|
{ |
52
|
|
|
$factory = new LineFormatterFactory(); |
53
|
|
|
|
54
|
|
|
$formatter = $factory($this->container, LineFormatter::class, $options); |
55
|
|
|
|
56
|
|
|
if (isset($options['date_format'])) { |
57
|
|
|
$this->assertSame($options['date_format'], $formatter->getDateFormat()); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
if (isset($options['max_normalize_depth'])) { |
61
|
|
|
$this->assertSame($options['max_normalize_depth'], $formatter->getMaxNormalizeDepth()); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
$this->assertInstanceOf(LineFormatter::class, $formatter); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return array<mixed> |
69
|
|
|
*/ |
70
|
|
|
public function getInvokeWillReturnConfiguredLineFormatterInstanceData(): array |
71
|
|
|
{ |
72
|
|
|
return [ |
73
|
|
|
[ |
74
|
|
|
[], |
75
|
|
|
], |
76
|
|
|
[ |
77
|
|
|
[ |
78
|
|
|
'date_format' => 'Y-m-d H:i:s', |
79
|
|
|
], |
80
|
|
|
], |
81
|
|
|
[ |
82
|
|
|
[ |
83
|
|
|
'max_normalize_depth' => 100, |
84
|
|
|
], |
85
|
|
|
], |
86
|
|
|
[ |
87
|
|
|
[ |
88
|
|
|
'max_normalize_item_count' => 2000, |
89
|
|
|
'json_pretty_print' => true, |
90
|
|
|
'json_encode_options' => [ |
91
|
|
|
\JSON_THROW_ON_ERROR, |
92
|
|
|
] |
93
|
|
|
] |
94
|
|
|
], |
95
|
|
|
]; |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|