Passed
Push — master ( b547f3...f31bce )
by Alex
52s queued 11s
created

testImplementsFactoryInterface()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 2
c 1
b 1
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\DateTime\Factory;
6
7
use Arp\DateTime\DateTimeFactory;
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\TestCase;
13
14
/**
15
 * @author  Alex Patterson <[email protected]>
16
 * @package ArpTest\DateTime\Factory
17
 */
18
final class CurrentDateTimeProviderFactoryTest extends TestCase
19
{
20
    /**
21
     * Ensure that the CurrentDateTimeProviderFactory implements the FactoryInterface.
22
     *
23
     * @covers \Arp\DateTime\Factory\CurrentDateTimeProviderFactory
24
     */
25
    public function testImplementsFactoryInterface(): void
26
    {
27
        $factory = new CurrentDateTimeProviderFactory();
28
29
        $this->assertInstanceOf(FactoryInterface::class, $factory);
30
    }
31
32
    /**
33
     * Assert that if provided with a 'factory' configuration option to create() a new FactoryException
34
     * will be thrown.
35
     *
36
     * @covers \Arp\DateTime\Factory\CurrentDateTimeProviderFactory::create
37
     */
38
    public function testCreateWillThrowFactoryExceptionIfConfigIsNotAValidDateTimeFactory(): void
39
    {
40
        $factory = new CurrentDateTimeProviderFactory();
41
42
        $factoryName = \stdClass::class;
43
        $config = [
44
            'factory' => $factoryName,
45
        ];
46
47
        $this->expectException(FactoryException::class);
48
        $this->expectExceptionMessage(
49
            sprintf(
50
                'The factory argument must be a class that implements \'%s\'; \'%s\' provided in \'%s\'',
51
                DateTimeFactory::class,
52
                $factoryName,
53
                CurrentDateTimeProviderFactory::class
54
            )
55
        );
56
57
        $factory->create($config);
58
    }
59
60
    /**
61
     * Ensure that create() will return a configured CurrentDateTimeProvider instance.
62
     *
63
     * @param array $config The optional test configuration.
64
     *
65
     * @covers \Arp\DateTime\Factory\CurrentDateTimeProviderFactory::create
66
     */
67
    public function testCreateWillReturnADateTimeProvider(array $config = []): void
68
    {
69
        $factory = new CurrentDateTimeProviderFactory();
70
71
        $provider = $factory->create($config);
72
73
        $this->assertInstanceOf(DateTimeProviderInterface::class, $provider);
74
    }
75
}
76