Passed
Pull Request — master (#7)
by Alex
01:51
created

DateFactoryFactoryTest::getCreateData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 14
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ArpTest\DateTime\Factory;
6
7
use Arp\DateTime\DateFactoryInterface;
8
use Arp\DateTime\DateIntervalFactoryInterface;
9
use Arp\DateTime\DateTimeFactoryInterface;
10
use Arp\DateTime\Factory\DateFactoryFactory;
11
use Arp\Factory\FactoryInterface;
12
use PHPUnit\Framework\MockObject\MockObject;
13
use PHPUnit\Framework\TestCase;
14
15
/**
16
 * @covers  \Arp\DateTime\Factory\DateFactoryFactory
17
 *
18
 * @author  Alex Patterson <[email protected]>
19
 * @package ArpTest\DateTime\Factory
20
 */
21
final class DateFactoryFactoryTest extends TestCase
22
{
23
    /**
24
     * @var FactoryInterface|MockObject
25
     */
26
    private $dateTimeFactoryFactory;
27
28
    /**
29
     * @var FactoryInterface|MockObject
30
     */
31
    private $dateIntervalFactoryFactory;
32
33
    /**
34
     * Prepare test case dependencies
35
     */
36
    public function setUp(): void
37
    {
38
        $this->dateTimeFactoryFactory = $this->createMock(FactoryInterface::class);
39
40
        $this->dateIntervalFactoryFactory = $this->createMock(FactoryInterface::class);
41
    }
42
43
    /**
44
     * Assert that the class implements FactoryInterface
45
     */
46
    public function testImplementsFactoryInterface(): void
47
    {
48
        $factory = new DateFactoryFactory($this->dateTimeFactoryFactory, $this->dateIntervalFactoryFactory);
49
50
        $this->assertInstanceOf(FactoryInterface::class, $factory);
51
    }
52
53
    /**
54
     * @param array $config
55
     *
56
     * @dataProvider getCreateData
57
     *
58
     * @throws \Arp\Factory\Exception\FactoryException
59
     */
60
    public function testCreate(array $config): void
61
    {
62
        $factory = new DateFactoryFactory($this->dateTimeFactoryFactory, $this->dateIntervalFactoryFactory);
63
64
        $dateTimeFactoryConfig = $config['date_time_factory'] ?? [];
65
        if (is_array($dateTimeFactoryConfig)) {
66
            $dateTimeFactory = $this->createMock(DateTimeFactoryInterface::class);
67
            $this->dateTimeFactoryFactory->expects($this->once())
68
                ->method('create')
69
                ->with($dateTimeFactoryConfig)
70
                ->willReturn($dateTimeFactory);
71
        }
72
73
        $dateIntervalFactoryConfig = $config['date_interval_factory'] ?? [];
74
        if (is_array($dateIntervalFactoryConfig)) {
75
            $dateIntervalFactory = $this->createMock(DateIntervalFactoryInterface::class);
76
            $this->dateIntervalFactoryFactory->expects($this->once())
77
                ->method('create')
78
                ->with($dateIntervalFactoryConfig)
79
                ->willReturn($dateIntervalFactory);
80
        }
81
82
        $this->assertInstanceOf(DateFactoryInterface::class, $factory->create($config));
83
    }
84
85
    /**
86
     * @return array
87
     */
88
    public function getCreateData(): array
89
    {
90
        return [
91
            [
92
                []
93
            ],
94
            [
95
                [
96
                    'date_time_factory' => []
97
                ],
98
            ],
99
            [
100
                [
101
                    'date_time_factory' => []
102
                ],
103
            ],
104
        ];
105
    }
106
}
107