Test Failed
Pull Request — master (#2)
by Alex
02:36
created

DateTimeFactoryFactoryTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 11
c 1
b 0
f 0
dl 0
loc 46
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testInvokeWillReturnAValidDateIntervalFactoryInstance() 0 9 1
A testImplementsFactoryInterface() 0 5 1
A testInvokeWillThrowAServiceNotCreatedExceptionIfTheDateTimeClassIsInvalid() 0 12 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ArpTest\LaminasDateTime\Factory;
6
7
use Arp\DateTime\DateTimeFactory;
8
use Arp\LaminasDateTime\Factory\DateTimeFactoryFactory;
9
use Arp\LaminasFactory\FactoryInterface;
10
use PHPUnit\Framework\MockObject\MockObject;
11
use PHPUnit\Framework\TestCase;
12
use Psr\Container\ContainerExceptionInterface;
13
use Psr\Container\ContainerInterface;
14
15
/**
16
 * @covers  \Arp\LaminasDateTime\Factory\DateTimeFactoryFactory
17
 *
18
 * @author  Alex Patterson <[email protected]>
19
 * @package ArpTest\LaminasDateTime\Factory
20
 */
21
final class DateTimeFactoryFactoryTest extends TestCase
22
{
23
    /**
24
     * Assert the factory implements FactoryInterface
25
     */
26
    public function testImplementsFactoryInterface(): void
27
    {
28
        $factory = new DateTimeFactoryFactory();
29
30
        $this->assertInstanceOf(FactoryInterface::class, $factory);
31
    }
32
33
    /**
34
     * Assert that the factory will return a valid DateIntervalFactory instance
35
     *
36
     * @throws ContainerExceptionInterface
37
     */
38
    public function testInvokeWillReturnAValidDateIntervalFactoryInstance(): void
39
    {
40
        $factory = new DateTimeFactoryFactory();
41
42
        /** @var ContainerInterface&MockObject $container */
43
        $container = $this->createMock(ContainerInterface::class);
44
45
        /** @noinspection UnnecessaryAssertionInspection */
46
        $this->assertInstanceOf(DateTimeFactory::class, $factory($container, DateTimeFactory::class));
47
    }
48
49
    /**
50
     * Assert that the __invoke() method will throw a ServiceNotCreatedException if the DateTimeFactory cannot be
51
     * created with the provided date time class name string
52
     *
53
     * @throws ContainerExceptionInterface
54
     */
55
    public function testInvokeWillThrowAServiceNotCreatedExceptionIfTheDateTimeClassIsInvalid(): void
56
    {
57
        $factory = new DateTimeFactoryFactory();
58
59
        /** @var ContainerInterface&MockObject $container */
60
        $container = $this->createMock(ContainerInterface::class);
61
62
        $options = [
63
            'date_time_class_name' => \stdClass::class,
64
        ];
65
66
        $factory($container, DateTimeFactory::class, $options);
67
    }
68
}
69