This repository was archived by the owner on Jan 29, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 6 files changed +88
-54
lines changed Expand file tree Collapse file tree 6 files changed +88
-54
lines changed Original file line number Diff line number Diff line change 7
7
8
8
namespace ZendTest \EventManager \ListenerProvider ;
9
9
10
- use Closure ;
11
- use Zend \EventManager \ListenerProvider \AbstractListenerSubscriber ;
12
- use Zend \EventManager \ListenerProvider \PrioritizedListenerAttachmentInterface ;
13
-
14
10
class AbstractListenerSubscriberTest extends ListenerSubscriberTraitTest
15
11
{
16
12
/**
17
13
* {@inheritDoc}
18
14
*/
19
15
public function createProvider (callable $ attachmentCallback )
20
16
{
21
- return new class ($ attachmentCallback ) extends AbstractListenerSubscriber {
22
- /** @var callable */
23
- private $ attachmentCallback ;
24
-
25
- public function __construct (callable $ attachmentCallback )
26
- {
27
- $ this ->attachmentCallback = $ attachmentCallback ;
28
- }
29
-
30
- public function attach (PrioritizedListenerAttachmentInterface $ provider , $ priority = 1 )
31
- {
32
- $ attachmentCallback = $ this ->attachmentCallback ->bindTo ($ this , $ this );
33
- $ attachmentCallback ($ provider , $ priority );
34
- }
35
- };
17
+ return new TestAsset \ExtendedCallbackSubscriber ($ attachmentCallback );
36
18
}
37
19
}
Original file line number Diff line number Diff line change 10
10
use PHPUnit \Framework \TestCase ;
11
11
use Prophecy \Argument ;
12
12
use Psr \Container \ContainerInterface ;
13
- use stdClass ;
14
13
use Zend \EventManager \EventInterface ;
15
14
use Zend \EventManager \Exception \InvalidArgumentException ;
16
15
use Zend \EventManager \ListenerProvider \LazyListener ;
@@ -134,22 +133,7 @@ public function methodsToInvoke()
134
133
*/
135
134
public function testInvocationInvokesMethodDefinedInListener ($ method , $ expected )
136
135
{
137
- $ listener = new class {
138
- public function __invoke ($ e )
139
- {
140
- $ e ->value = __FUNCTION__ ;
141
- }
142
-
143
- public function run ($ e )
144
- {
145
- $ e ->value = __FUNCTION__ ;
146
- }
147
-
148
- public function onEvent ($ e )
149
- {
150
- $ e ->value = __FUNCTION__ ;
151
- }
152
- };
136
+ $ listener = new TestAsset \MultipleListener ();
153
137
154
138
$ this ->container
155
139
->get ('listener ' )
Original file line number Diff line number Diff line change 10
10
use PHPUnit \Framework \TestCase ;
11
11
use Prophecy \Argument ;
12
12
use Zend \EventManager \ListenerProvider \ListenerSubscriberInterface ;
13
- use Zend \EventManager \ListenerProvider \ListenerSubscriberTrait ;
14
13
use Zend \EventManager \ListenerProvider \PrioritizedListenerAttachmentInterface ;
15
14
16
15
class ListenerSubscriberTraitTest extends TestCase
@@ -20,23 +19,7 @@ class ListenerSubscriberTraitTest extends TestCase
20
19
*/
21
20
public function createProvider (callable $ attachmentCallback )
22
21
{
23
- return new class ($ attachmentCallback ) implements ListenerSubscriberInterface {
24
- use ListenerSubscriberTrait;
25
-
26
- /** @var callable */
27
- private $ attachmentCallback ;
28
-
29
- public function __construct (callable $ attachmentCallback )
30
- {
31
- $ this ->attachmentCallback = $ attachmentCallback ;
32
- }
33
-
34
- public function attach (PrioritizedListenerAttachmentInterface $ provider , $ priority = 1 )
35
- {
36
- $ attachmentCallback = $ this ->attachmentCallback ->bindTo ($ this , $ this );
37
- $ attachmentCallback ($ provider , $ priority );
38
- }
39
- };
22
+ return new TestAsset \CallbackSubscriber ($ attachmentCallback );
40
23
}
41
24
42
25
public function testSubscriberAttachesListeners ()
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * @see https://github.com/zendframework/zend-eventmanager for the canonical source repository
4
+ * @copyright Copyright (c) 2019 Zend Technologies USA Inc. (https://www.zend.com)
5
+ * @license https://github.com/zendframework/zend-eventmanager/blob/master/LICENSE.md New BSD License
6
+ */
7
+
8
+ namespace ZendTest \EventManager \ListenerProvider \TestAsset ;
9
+
10
+ use Zend \EventManager \ListenerProvider \ListenerSubscriberInterface ;
11
+ use Zend \EventManager \ListenerProvider \ListenerSubscriberTrait ;
12
+ use Zend \EventManager \ListenerProvider \PrioritizedListenerAttachmentInterface ;
13
+
14
+ class CallbackSubscriber implements ListenerSubscriberInterface
15
+ {
16
+ use ListenerSubscriberTrait;
17
+
18
+ /** @var callable */
19
+ private $ attachmentCallback ;
20
+
21
+ public function __construct (callable $ attachmentCallback )
22
+ {
23
+ $ this ->attachmentCallback = $ attachmentCallback ;
24
+ }
25
+
26
+ public function attach (PrioritizedListenerAttachmentInterface $ provider , $ priority = 1 )
27
+ {
28
+ $ attachmentCallback = $ this ->attachmentCallback ->bindTo ($ this , $ this );
29
+ $ attachmentCallback ($ provider , $ priority );
30
+ }
31
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * @see https://github.com/zendframework/zend-eventmanager for the canonical source repository
4
+ * @copyright Copyright (c) 2019 Zend Technologies USA Inc. (https://www.zend.com)
5
+ * @license https://github.com/zendframework/zend-eventmanager/blob/master/LICENSE.md New BSD License
6
+ */
7
+
8
+ namespace ZendTest \EventManager \ListenerProvider \TestAsset ;
9
+
10
+ use Zend \EventManager \ListenerProvider \AbstractListenerSubscriber ;
11
+ use Zend \EventManager \ListenerProvider \PrioritizedListenerAttachmentInterface ;
12
+
13
+ class ExtendedCallbackSubscriber extends AbstractListenerSubscriber
14
+ {
15
+ /** @var callable */
16
+ private $ attachmentCallback ;
17
+
18
+ public function __construct (callable $ attachmentCallback )
19
+ {
20
+ $ this ->attachmentCallback = $ attachmentCallback ;
21
+ }
22
+
23
+ public function attach (PrioritizedListenerAttachmentInterface $ provider , $ priority = 1 )
24
+ {
25
+ $ attachmentCallback = $ this ->attachmentCallback ->bindTo ($ this , $ this );
26
+ $ attachmentCallback ($ provider , $ priority );
27
+ }
28
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * @see https://github.com/zendframework/zend-eventmanager for the canonical source repository
4
+ * @copyright Copyright (c) 2019 Zend Technologies USA Inc. (https://www.zend.com)
5
+ * @license https://github.com/zendframework/zend-eventmanager/blob/master/LICENSE.md New BSD License
6
+ */
7
+
8
+ namespace ZendTest \EventManager \ListenerProvider \TestAsset ;
9
+
10
+ class MultipleListener
11
+ {
12
+ public function __invoke ($ e )
13
+ {
14
+ $ e ->value = __FUNCTION__ ;
15
+ }
16
+
17
+ public function run ($ e )
18
+ {
19
+ $ e ->value = __FUNCTION__ ;
20
+ }
21
+
22
+ public function onEvent ($ e )
23
+ {
24
+ $ e ->value = __FUNCTION__ ;
25
+ }
26
+ }
You can’t perform that action at this time.
0 commit comments