Passed
Push — master ( 02ad68...578058 )
by Alex
01:35 queued 13s
created

testImplementsFactoryInterface()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 0
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\JsonFormatterFactory;
9
use Laminas\ServiceManager\Exception\ServiceNotCreatedException;
10
use Monolog\Formatter\JsonFormatter;
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\JsonFormatterFactory
18
 * @covers \Arp\LaminasMonolog\Factory\Formatter\AbstractNormalizerFormatterFactory
19
 *
20
 * @author  Alex Patterson <[email protected]>
21
 * @package ArpTest\LaminasMonolog\Factory\Formatter
22
 */
23
final class JsonFormatterFactoryTest 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 JsonFormatterFactory();
38
39
        $this->assertInstanceOf(FactoryInterface::class, $factory);
40
    }
41
42
    /**
43
     * @dataProvider getInvokeReturnsConfiguredJsonFormatterInstanceData
44
     *
45
     * @param array<mixed> $options
46
     *
47
     * @throws ServiceNotCreatedException
48
     * @throws ContainerExceptionInterface
49
     */
50
    public function testInvokeReturnsConfiguredJsonFormatterInstance(array $options): void
51
    {
52
        $factory = new JsonFormatterFactory();
53
54
        $formatter = $factory($this->container, JsonFormatter::class, $options);
55
56
        $this->assertSame(
57
            $options['batch_mode'] ?? JsonFormatter::BATCH_MODE_JSON,
58
            $formatter->getBatchMode()
59
        );
60
61
        $this->assertSame(
62
            $options['append_new_line'] ?? true,
63
            $formatter->isAppendingNewlines()
64
        );
65
66
        if (isset($options['date_format'])) {
67
            $this->assertSame($options['date_format'], $formatter->getDateFormat());
68
        }
69
70
        if (isset($options['max_normalize_depth'])) {
71
            $this->assertSame($options['max_normalize_depth'], $formatter->getMaxNormalizeDepth());
72
        }
73
74
        $this->assertInstanceOf(JsonFormatter::class, $formatter);
75
    }
76
77
    /**
78
     * @return array<mixed>
79
     */
80
    public function getInvokeReturnsConfiguredJsonFormatterInstanceData(): array
81
    {
82
        return [
83
            [
84
                [],
85
            ],
86
            [
87
                [
88
                    'batch_mode' => JsonFormatter::BATCH_MODE_NEWLINES,
89
                ]
90
            ],
91
            [
92
                [
93
                    'append_new_line' => false,
94
                    'ignore_empty_context_and_extra' => true,
95
                    'include_stack_traces' => true,
96
                ]
97
            ],
98
            [
99
                [
100
                    'date_format' => 'Y-m-d H:i:s',
101
                ]
102
            ],
103
            [
104
                [
105
                    'max_normalize_depth' => 1234,
106
                ]
107
            ]
108
        ];
109
    }
110
}
111