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\HtmlFormatterFactory; |
9
|
|
|
use Laminas\ServiceManager\Exception\ServiceNotCreatedException; |
10
|
|
|
use Monolog\Formatter\HtmlFormatter; |
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\HtmlFormatterFactory |
18
|
|
|
* @covers \Arp\LaminasMonolog\Factory\Formatter\AbstractNormalizerFormatterFactory |
19
|
|
|
*/ |
20
|
|
|
final class HtmlFormatterFactoryTest 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 HtmlFormatterFactory(); |
35
|
|
|
|
36
|
|
|
$this->assertInstanceOf(FactoryInterface::class, $factory); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @dataProvider getInvokeWillReturnConfiguredHtmlFormatterInstanceData |
41
|
|
|
* |
42
|
|
|
* @param array<mixed> $options |
43
|
|
|
* |
44
|
|
|
* @throws ServiceNotCreatedException |
45
|
|
|
* @throws ContainerExceptionInterface |
46
|
|
|
*/ |
47
|
|
|
public function testInvokeWillReturnConfiguredHtmlFormatterInstance(array $options): void |
48
|
|
|
{ |
49
|
|
|
$factory = new HtmlFormatterFactory(); |
50
|
|
|
|
51
|
|
|
$formatter = $factory($this->container, HtmlFormatter::class, $options); |
52
|
|
|
|
53
|
|
|
if (isset($options['date_format'])) { |
54
|
|
|
$this->assertSame($options['date_format'], $formatter->getDateFormat()); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$this->assertInstanceOf(HtmlFormatter::class, $formatter); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return array<mixed> |
62
|
|
|
*/ |
63
|
|
|
public function getInvokeWillReturnConfiguredHtmlFormatterInstanceData(): array |
64
|
|
|
{ |
65
|
|
|
return [ |
66
|
|
|
[ |
67
|
|
|
[], |
68
|
|
|
], |
69
|
|
|
[ |
70
|
|
|
[ |
71
|
|
|
'date_format' => 'Y-m-d H:i:s', |
72
|
|
|
] |
73
|
|
|
] |
74
|
|
|
]; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|