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 Laminas\ServiceManager\Exception\ServiceNotCreatedException; |
11
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
12
|
|
|
use PHPUnit\Framework\TestCase; |
13
|
|
|
use Psr\Container\ContainerExceptionInterface; |
14
|
|
|
use Psr\Container\ContainerInterface; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @covers \Arp\LaminasDateTime\Factory\DateTimeFactoryFactory |
18
|
|
|
* |
19
|
|
|
* @author Alex Patterson <[email protected]> |
20
|
|
|
* @package ArpTest\LaminasDateTime\Factory |
21
|
|
|
*/ |
22
|
|
|
final class DateTimeFactoryFactoryTest extends TestCase |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Assert the factory implements FactoryInterface |
26
|
|
|
*/ |
27
|
|
|
public function testImplementsFactoryInterface(): void |
28
|
|
|
{ |
29
|
|
|
$factory = new DateTimeFactoryFactory(); |
30
|
|
|
|
31
|
|
|
$this->assertInstanceOf(FactoryInterface::class, $factory); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Assert that the factory will return a valid DateIntervalFactory instance |
36
|
|
|
* |
37
|
|
|
* @throws ContainerExceptionInterface |
38
|
|
|
*/ |
39
|
|
|
public function testInvokeWillReturnAValidDateIntervalFactoryInstance(): void |
40
|
|
|
{ |
41
|
|
|
$factory = new DateTimeFactoryFactory(); |
42
|
|
|
|
43
|
|
|
/** @var ContainerInterface&MockObject $container */ |
44
|
|
|
$container = $this->createMock(ContainerInterface::class); |
45
|
|
|
|
46
|
|
|
/** @noinspection UnnecessaryAssertionInspection */ |
47
|
|
|
$this->assertInstanceOf(DateTimeFactory::class, $factory($container, DateTimeFactory::class, [])); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Assert that the __invoke() method will throw a ServiceNotCreatedException if the DateTimeFactory cannot be |
52
|
|
|
* created with the provided date time class name string |
53
|
|
|
* |
54
|
|
|
* @throws ContainerExceptionInterface |
55
|
|
|
*/ |
56
|
|
|
public function testInvokeWillThrowAServiceNotCreatedExceptionIfTheDateTimeClassIsInvalid(): void |
57
|
|
|
{ |
58
|
|
|
$factory = new DateTimeFactoryFactory(); |
59
|
|
|
|
60
|
|
|
/** @var ContainerInterface&MockObject $container */ |
61
|
|
|
$container = $this->createMock(ContainerInterface::class); |
62
|
|
|
|
63
|
|
|
$options = [ |
64
|
|
|
'date_time_class_name' => \stdClass::class, |
65
|
|
|
]; |
66
|
|
|
|
67
|
|
|
$this->expectException(ServiceNotCreatedException::class); |
68
|
|
|
$this->expectExceptionMessage('Failed to create date time factory:'); |
69
|
|
|
|
70
|
|
|
$factory($container, DateTimeFactory::class, $options); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|