Passed
Pull Request — master (#7)
by Alex
07:24
created

testCreateWillThrowFactoryExceptionWithInvalidConfiguration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 8
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ArpTest\DateTime\Factory;
6
7
use Arp\DateTime\DateTimeFactory;
8
use Arp\DateTime\Factory\DateTimeFactoryFactory;
9
use Arp\Factory\Exception\FactoryException;
10
use Arp\Factory\FactoryInterface;
11
use PHPUnit\Framework\TestCase;
12
13
/**
14
 * @covers  \Arp\DateTime\Factory\DateTimeFactoryFactory
15
 *
16
 * @author  Alex Patterson <[email protected]>
17
 * @package ArpTest\DateTime\Factory
18
 */
19
final class DateTimeFactoryFactoryTest extends TestCase
20
{
21
    /**
22
     * Assert that the factory implements FactoryInterface
23
     */
24
    public function testImplementsFactoryInterface(): void
25
    {
26
        $factory = new DateTimeFactoryFactory();
27
28
        $this->assertInstanceOf(FactoryInterface::class, $factory);
29
    }
30
31
    /**
32
     * Assert that FactoryException are thrown when providing invalid $config to create()
33
     *
34
     * @param array $config
35
     *
36
     * @dataProvider getCreateWillThrowFactoryExceptionWithInvalidConfigurationData
37
     *
38
     * @throws FactoryException
39
     */
40
    public function testCreateWillThrowFactoryExceptionWithInvalidConfiguration(array $config): void
41
    {
42
        $factory = new DateTimeFactoryFactory();
43
44
        $this->expectException(FactoryException::class);
45
        $this->expectExceptionMessage('Failed to create DateTimeFactory');
46
47
        $factory->create($config);
48
    }
49
50
    /**
51
     * @return array
52
     */
53
    public function getCreateWillThrowFactoryExceptionWithInvalidConfigurationData(): array
54
    {
55
        return [
56
            [
57
                [
58
                    'date_class_name' => \stdClass::class,
59
                ],
60
            ],
61
            [
62
                [
63
                    'time_zone_class_name' => \stdClass::class,
64
                ],
65
            ],
66
        ];
67
    }
68
69
    /**
70
     * Assert that the factory will return a DateTimeFactory instance when calling create()
71
     *
72
     * @param array $config
73
     *
74
     * @dataProvider getCreateWillReturnADateTimeFactoryData
75
     *
76
     * @throws FactoryException
77
     */
78
    public function testCreateWillReturnADateTimeFactory(array $config): void
79
    {
80
        $factory = new DateTimeFactoryFactory();
81
82
        $this->assertInstanceOf(DateTimeFactory::class, $factory->create($config));
83
    }
84
85
    /**
86
     * @return array
87
     */
88
    public function getCreateWillReturnADateTimeFactoryData(): array
89
    {
90
        return [
91
            [
92
                [],
93
            ],
94
            [
95
                [
96
                    'date_class_name' => \DateTime::class,
97
                ],
98
            ],
99
            [
100
                [
101
                    'date_class_name' => \DateTimeImmutable::class,
102
                ],
103
            ],
104
            [
105
                [
106
                    'time_zone_class_name' => \DateTimeZone::class,
107
                ],
108
            ],
109
        ];
110
    }
111
}
112