Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit df2b093

Browse files
committed
refactor: Make anonymous classes into actual test asset classes
Required to allow us to test against PHP 5.6.
1 parent 441e8dd commit df2b093

File tree

6 files changed

+88
-54
lines changed

6 files changed

+88
-54
lines changed

test/ListenerProvider/AbstractListenerSubscriberTest.php

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,13 @@
77

88
namespace ZendTest\EventManager\ListenerProvider;
99

10-
use Closure;
11-
use Zend\EventManager\ListenerProvider\AbstractListenerSubscriber;
12-
use Zend\EventManager\ListenerProvider\PrioritizedListenerAttachmentInterface;
13-
1410
class AbstractListenerSubscriberTest extends ListenerSubscriberTraitTest
1511
{
1612
/**
1713
* {@inheritDoc}
1814
*/
1915
public function createProvider(callable $attachmentCallback)
2016
{
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);
3618
}
3719
}

test/ListenerProvider/LazyListenerTest.php

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use PHPUnit\Framework\TestCase;
1111
use Prophecy\Argument;
1212
use Psr\Container\ContainerInterface;
13-
use stdClass;
1413
use Zend\EventManager\EventInterface;
1514
use Zend\EventManager\Exception\InvalidArgumentException;
1615
use Zend\EventManager\ListenerProvider\LazyListener;
@@ -134,22 +133,7 @@ public function methodsToInvoke()
134133
*/
135134
public function testInvocationInvokesMethodDefinedInListener($method, $expected)
136135
{
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();
153137

154138
$this->container
155139
->get('listener')

test/ListenerProvider/ListenerSubscriberTraitTest.php

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use PHPUnit\Framework\TestCase;
1111
use Prophecy\Argument;
1212
use Zend\EventManager\ListenerProvider\ListenerSubscriberInterface;
13-
use Zend\EventManager\ListenerProvider\ListenerSubscriberTrait;
1413
use Zend\EventManager\ListenerProvider\PrioritizedListenerAttachmentInterface;
1514

1615
class ListenerSubscriberTraitTest extends TestCase
@@ -20,23 +19,7 @@ class ListenerSubscriberTraitTest extends TestCase
2019
*/
2120
public function createProvider(callable $attachmentCallback)
2221
{
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);
4023
}
4124

4225
public function testSubscriberAttachesListeners()
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
}

0 commit comments

Comments
 (0)