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

testImplementsFactoryInterface()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
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\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