1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace ArpTest\EventDispatcher\Listener; |
6
|
|
|
|
7
|
|
|
use Arp\EventDispatcher\Listener\Exception\EventListenerException; |
8
|
|
|
use Arp\EventDispatcher\Listener\LazyListener; |
|
|
|
|
9
|
|
|
use PHPUnit\Framework\ExpectationFailedException; |
10
|
|
|
use PHPUnit\Framework\TestCase; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @covers \Arp\EventDispatcher\Listener\LazyListener |
14
|
|
|
*/ |
15
|
|
|
final class LazyListenerTest extends TestCase |
16
|
|
|
{ |
17
|
|
|
public function testIsCallable(): void |
18
|
|
|
{ |
19
|
|
|
$listener = new LazyListener( |
20
|
|
|
static function () { |
21
|
|
|
} |
22
|
|
|
); |
23
|
|
|
|
24
|
|
|
$this->assertIsCallable($listener); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @throws EventListenerException |
29
|
|
|
*/ |
30
|
|
|
public function testInvokeWillThrowEventListenerExceptionIfTheFactoryMethodIsNotCallable(): void |
31
|
|
|
{ |
32
|
|
|
$event = new \stdClass(); |
33
|
|
|
$factory = new \stdClass(); |
34
|
|
|
|
35
|
|
|
$lazyListener = new LazyListener($factory); |
36
|
|
|
|
37
|
|
|
$this->expectException(EventListenerException::class); |
38
|
|
|
$this->expectExceptionMessage( |
39
|
|
|
sprintf( |
40
|
|
|
'The method \'%s\' is not callable for lazy load factory \'%s\'', |
41
|
|
|
'__invoke', |
42
|
|
|
'array' |
43
|
|
|
) |
44
|
|
|
); |
45
|
|
|
|
46
|
|
|
$lazyListener($event); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @throws EventListenerException |
51
|
|
|
*/ |
52
|
|
|
public function testInvokeWillThrowEventListenerExceptionIfTheListenerMethodIsNotCallable(): void |
53
|
|
|
{ |
54
|
|
|
$event = new \stdClass(); |
55
|
|
|
$listener = new \stdClass(); |
56
|
|
|
$factory = static fn () => $listener; |
57
|
|
|
|
58
|
|
|
$lazyListener = new LazyListener($factory); |
59
|
|
|
|
60
|
|
|
$this->expectException(EventListenerException::class); |
61
|
|
|
$this->expectExceptionMessage( |
62
|
|
|
sprintf( |
63
|
|
|
'The method \'%s\' is not callable for lazy load event listener \'%s\'', |
64
|
|
|
'__invoke', |
65
|
|
|
'array' |
66
|
|
|
) |
67
|
|
|
); |
68
|
|
|
|
69
|
|
|
$lazyListener($event); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @throws EventListenerException |
74
|
|
|
* @throws ExpectationFailedException |
75
|
|
|
* |
76
|
|
|
* @dataProvider getLazyListenerWillCreateAndDispatchEventData |
77
|
|
|
*/ |
78
|
|
|
public function testLazyListenerWillCreateAndDispatchEvent( |
79
|
|
|
mixed $expected, |
80
|
|
|
mixed $factory, |
81
|
|
|
?string $factoryMethod = null, |
82
|
|
|
?string $listenerMethod = null |
83
|
|
|
): void { |
84
|
|
|
$event = new \stdClass(); |
85
|
|
|
$lazyListener = new LazyListener($factory, $factoryMethod, $listenerMethod); |
86
|
|
|
|
87
|
|
|
$this->assertSame($expected, $lazyListener($event)); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return array<mixed> |
92
|
|
|
*/ |
93
|
|
|
public function getLazyListenerWillCreateAndDispatchEventData(): array |
94
|
|
|
{ |
95
|
|
|
$factory1 = new class () { |
96
|
|
|
public function create(): callable |
97
|
|
|
{ |
98
|
|
|
return static fn () => 'hello123'; |
99
|
|
|
} |
100
|
|
|
}; |
101
|
|
|
|
102
|
|
|
$listener1 = new class () { |
103
|
|
|
public function doSomething(object $event): string |
|
|
|
|
104
|
|
|
{ |
105
|
|
|
return 'test123'; |
106
|
|
|
} |
107
|
|
|
}; |
108
|
|
|
|
109
|
|
|
$factory2 = new class ($listener1) { |
110
|
|
|
private object $listener; |
111
|
|
|
|
112
|
|
|
public function __construct(object $listener) |
113
|
|
|
{ |
114
|
|
|
$this->listener = $listener; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function create(): object |
118
|
|
|
{ |
119
|
|
|
return $this->listener; |
120
|
|
|
} |
121
|
|
|
}; |
122
|
|
|
|
123
|
|
|
return [ |
124
|
|
|
[ |
125
|
|
|
'hello123', |
126
|
|
|
static fn () => static fn () => 'hello123', |
127
|
|
|
], |
128
|
|
|
|
129
|
|
|
[ |
130
|
|
|
'hello123', |
131
|
|
|
$factory1, |
132
|
|
|
'create' |
133
|
|
|
], |
134
|
|
|
|
135
|
|
|
[ |
136
|
|
|
'test123', |
137
|
|
|
$factory2, |
138
|
|
|
'create', |
139
|
|
|
'doSomething', |
140
|
|
|
] |
141
|
|
|
]; |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths