1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace ArpTest\LaminasMonolog\Factory\Handler; |
6
|
|
|
|
7
|
|
|
use Arp\LaminasFactory\FactoryInterface; |
8
|
|
|
use Arp\LaminasMonolog\Factory\Handler\StreamHandlerFactory; |
9
|
|
|
use Laminas\ServiceManager\Exception\ServiceNotCreatedException; |
10
|
|
|
use Monolog\Handler\StreamHandler; |
11
|
|
|
use Monolog\Test\TestCase; |
12
|
|
|
use Psr\Container\ContainerExceptionInterface; |
13
|
|
|
use Psr\Container\ContainerInterface; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @covers \Arp\LaminasMonolog\Factory\Handler\StreamHandlerFactory |
17
|
|
|
*/ |
18
|
|
|
final class StreamHandlerFactoryTest extends TestCase |
19
|
|
|
{ |
20
|
|
|
private ContainerInterface $container; |
21
|
|
|
|
22
|
|
|
public function setUp(): void |
23
|
|
|
{ |
24
|
|
|
$this->container = $this->createMock(ContainerInterface::class); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function testImplementsFactoryInterface(): void |
28
|
|
|
{ |
29
|
|
|
$handler = new StreamHandlerFactory(); |
30
|
|
|
$this->assertInstanceOf(FactoryInterface::class, $handler); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @throws ServiceNotCreatedException |
35
|
|
|
* @throws ContainerExceptionInterface |
36
|
|
|
*/ |
37
|
|
|
public function testMissingStreamConfigurationThrowsServiceNotCreatedException(): void |
38
|
|
|
{ |
39
|
|
|
$handler = new StreamHandlerFactory(); |
40
|
|
|
|
41
|
|
|
$requestedName = StreamHandlerFactory::class; |
42
|
|
|
|
43
|
|
|
$this->expectException(ServiceNotCreatedException::class); |
44
|
|
|
$this->expectExceptionMessage( |
45
|
|
|
sprintf('The required \'stream\' configuration option is missing for service \'%s\'', $requestedName) |
46
|
|
|
); |
47
|
|
|
|
48
|
|
|
$handler($this->container, $requestedName, []); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @throws ContainerExceptionInterface |
53
|
|
|
*/ |
54
|
|
|
public function testInvalidClassNameConfigurationThrowsServiceNotCreatedException(): void |
55
|
|
|
{ |
56
|
|
|
$handler = new StreamHandlerFactory(); |
57
|
|
|
|
58
|
|
|
$requestedName = StreamHandlerFactory::class; |
59
|
|
|
|
60
|
|
|
$options = [ |
61
|
|
|
'class_name' => \stdClass::class, |
62
|
|
|
'stream' => 'stream value', |
63
|
|
|
]; |
64
|
|
|
|
65
|
|
|
$this->expectException(ServiceNotCreatedException::class); |
66
|
|
|
$this->expectExceptionMessage( |
67
|
|
|
sprintf( |
68
|
|
|
'The stream handler provided via configuration option \'class_name\' is invalid: ' |
69
|
|
|
. 'The stream handler class must extend from \'%s\'; \'%s\' provided for service \'%s\'', |
70
|
|
|
StreamHandler::class, |
71
|
|
|
$options['class_name'], |
72
|
|
|
$requestedName, |
73
|
|
|
), |
74
|
|
|
); |
75
|
|
|
|
76
|
|
|
$handler($this->container, $requestedName, $options); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|