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