Passed
Pull Request — master (#7)
by Alex
12:47
created

testCreateWillThrowFactoryExceptionIfConfigIsNotAValidDateTimeFactory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 12
c 1
b 1
f 0
dl 0
loc 20
rs 9.8666
cc 1
nc 1
nop 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A CurrentDateTimeProviderFactoryTest::testImplementsFactoryInterface() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ArpTest\DateTime\Factory;
6
7
use Arp\DateTime\DateTimeFactoryInterface;
8
use Arp\DateTime\DateTimeProviderInterface;
9
use Arp\DateTime\Factory\CurrentDateTimeProviderFactory;
10
use Arp\Factory\Exception\FactoryException;
11
use Arp\Factory\FactoryInterface;
12
use PHPUnit\Framework\MockObject\MockObject;
13
use PHPUnit\Framework\TestCase;
14
15
/**
16
 * @author  Alex Patterson <[email protected]>
17
 * @package ArpTest\DateTime\Factory
18
 */
19
final class CurrentDateTimeProviderFactoryTest extends TestCase
20
{
21
    /**
22
     * @var FactoryInterface|MockObject
23
     */
24
    private $dateTimeFactoryFactory;
25
26
    /**
27
     * Set up the test case dependencies
28
     */
29
    public function setUp(): void
30
    {
31
        $this->dateTimeFactoryFactory = $this->createMock(FactoryInterface::class);
32
    }
33
34
    /**
35
     * Ensure that the CurrentDateTimeProviderFactory implements the FactoryInterface.
36
     *
37
     * @covers \Arp\DateTime\Factory\CurrentDateTimeProviderFactory
38
     */
39
    public function testImplementsFactoryInterface(): void
40
    {
41
        $factory = new CurrentDateTimeProviderFactory($this->dateTimeFactoryFactory);
42
43
        $this->assertInstanceOf(FactoryInterface::class, $factory);
44
    }
45
46
    /**
47
     * Ensure that create() will return a configured CurrentDateTimeProvider instance.
48
     *
49
     * @param array $config The optional test configuration.
50
     *
51
     * @dataProvider getCreateWillReturnADateTimeProviderData
52
     * @covers \Arp\DateTime\Factory\CurrentDateTimeProviderFactory::create
53
     *
54
     * @throws FactoryException
55
     */
56
    public function testCreateWillReturnADateTimeProvider(array $config = []): void
57
    {
58
        $factory = new CurrentDateTimeProviderFactory($this->dateTimeFactoryFactory);
59
60
        $dateTimeFactoryConfig = $config['date_time_factory'] ?? [];
61
        if (is_array($dateTimeFactoryConfig)) {
62
            /** @var DateTimeFactoryInterface|MockObject $dateTimeFactory */
63
            $this->dateTimeFactoryFactory->expects($this->once())
64
                ->method('create')
65
                ->with($dateTimeFactoryConfig)
66
                ->willReturn($this->createMock(DateTimeFactoryInterface::class));
67
        }
68
69
        $this->assertInstanceOf(DateTimeProviderInterface::class, $factory->create($config));
70
    }
71
72
    /**
73
     * @return array
74
     */
75
    public function getCreateWillReturnADateTimeProviderData(): array
76
    {
77
        return [
78
            [
79
                [],
80
            ],
81
            [
82
                [
83
                    'date_time_factory' => $this->createMock(DateTimeFactoryInterface::class)
84
                ],
85
            ],
86
        ];
87
    }
88
}
89