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
|
|
|
* @author Alex Patterson <[email protected]> |
21
|
|
|
* @package ArpTest\LaminasMonolog\Factory\Formatter |
22
|
|
|
*/ |
23
|
|
|
final class HtmlFormatterFactoryTest 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 HtmlFormatterFactory(); |
38
|
|
|
|
39
|
|
|
$this->assertInstanceOf(FactoryInterface::class, $factory); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @dataProvider getInvokeWillReturnConfiguredHtmlFormatterInstanceData |
44
|
|
|
* |
45
|
|
|
* @param array<mixed> $options |
46
|
|
|
* |
47
|
|
|
* @throws ServiceNotCreatedException |
48
|
|
|
* @throws ContainerExceptionInterface |
49
|
|
|
*/ |
50
|
|
|
public function testInvokeWillReturnConfiguredHtmlFormatterInstance(array $options): void |
51
|
|
|
{ |
52
|
|
|
$factory = new HtmlFormatterFactory(); |
53
|
|
|
|
54
|
|
|
$formatter = $factory($this->container, HtmlFormatter::class, $options); |
55
|
|
|
|
56
|
|
|
if (isset($options['date_format'])) { |
57
|
|
|
$this->assertSame($options['date_format'], $formatter->getDateFormat()); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$this->assertInstanceOf(HtmlFormatter::class, $formatter); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return array<mixed> |
65
|
|
|
*/ |
66
|
|
|
public function getInvokeWillReturnConfiguredHtmlFormatterInstanceData(): array |
67
|
|
|
{ |
68
|
|
|
return [ |
69
|
|
|
[ |
70
|
|
|
[], |
71
|
|
|
], |
72
|
|
|
[ |
73
|
|
|
[ |
74
|
|
|
'date_format' => 'Y-m-d H:i:s', |
75
|
|
|
] |
76
|
|
|
] |
77
|
|
|
]; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|