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

Commit 64c766d

Browse files
snapshotplXerkus
authored andcommitted
Remove v2 support from tests
1 parent abf9c4e commit 64c766d

11 files changed

+27
-361
lines changed

src/Controller/Plugin/Forward.php

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -180,20 +180,9 @@ protected function detachProblemListeners(SharedEvents $sharedEvents)
180180
$results[$id][$eventName] = [];
181181
$events = $this->getSharedListenersById($id, $eventName, $sharedEvents);
182182
foreach ($events as $priority => $currentPriorityEvents) {
183-
// v2 fix
184-
if (!is_array($currentPriorityEvents)) {
185-
$currentPriorityEvents = [$currentPriorityEvents];
186-
}
187-
// v3
188183
foreach ($currentPriorityEvents as $currentEvent) {
189184
$currentCallback = $currentEvent;
190185

191-
// zend-eventmanager v2 compatibility:
192-
if ($currentCallback instanceof CallbackHandler) {
193-
$currentCallback = $currentEvent->getCallback();
194-
$priority = $currentEvent->getMetadatum('priority');
195-
}
196-
197186
// If we have an array, grab the object
198187
if (is_array($currentCallback)) {
199188
$currentCallback = array_shift($currentCallback);
@@ -203,16 +192,6 @@ protected function detachProblemListeners(SharedEvents $sharedEvents)
203192
if (!is_object($currentCallback)) {
204193
continue;
205194
}
206-
207-
foreach ($classArray as $class) {
208-
if ($currentCallback instanceof $class) {
209-
// Pass $currentEvent; when using zend-eventmanager v2,
210-
// this is the CallbackHandler, while in v3 it's
211-
// the actual listener.
212-
$this->detachSharedListener($id, $currentEvent, $sharedEvents);
213-
$results[$id][$eventName][$priority] = $currentEvent;
214-
}
215-
}
216195
}
217196
}
218197
}
@@ -235,12 +214,6 @@ protected function reattachProblemListeners(SharedEvents $sharedEvents, array $l
235214
foreach ($callbacks as $priority => $current) {
236215
$callback = $current;
237216

238-
// zend-eventmanager v2 compatibility:
239-
if ($current instanceof CallbackHandler) {
240-
$callback = $current->getCallback();
241-
$priority = $current->getMetadatum('priority');
242-
}
243-
244217
$sharedEvents->attach($id, $eventName, $callback, $priority);
245218
}
246219
}
@@ -293,12 +266,6 @@ protected function getEvent()
293266
*/
294267
private function getSharedListenersById($id, $event, SharedEvents $sharedEvents)
295268
{
296-
if (method_exists($sharedEvents, 'attachAggregate')) {
297-
// v2
298-
return $sharedEvents->getListeners($id, $event) ?: [];
299-
}
300-
301-
// v3
302269
return $sharedEvents->getListeners([$id], $event);
303270
}
304271

@@ -314,13 +281,6 @@ private function getSharedListenersById($id, $event, SharedEvents $sharedEvents)
314281
*/
315282
private function detachSharedListener($id, $listener, SharedEvents $sharedEvents)
316283
{
317-
if (method_exists($sharedEvents, 'attachAggregate')) {
318-
// v2
319-
$sharedEvents->detach($id, $listener);
320-
return;
321-
}
322-
323-
// v3
324284
$sharedEvents->detach($listener, $id);
325285
}
326286
}

src/Controller/PluginManager.php

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public function injectController($plugin)
148148
}
149149

150150
/**
151-
* Validate a plugin (v3)
151+
* Validate a plugin
152152
*
153153
* {@inheritDoc}
154154
*/
@@ -162,24 +162,4 @@ public function validate($plugin)
162162
));
163163
}
164164
}
165-
166-
/**
167-
* Validate a plugin (v2)
168-
*
169-
* {@inheritDoc}
170-
*
171-
* @throws Exception\InvalidPluginException
172-
*/
173-
public function validatePlugin($plugin)
174-
{
175-
try {
176-
$this->validate($plugin);
177-
} catch (InvalidServiceException $e) {
178-
throw new Exception\InvalidPluginException(
179-
$e->getMessage(),
180-
$e->getCode(),
181-
$e
182-
);
183-
}
184-
}
185165
}

test/Controller/ControllerManagerTest.php

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,7 @@ public function testCanInjectEventManager()
6464
{
6565
$controller = new TestAsset\SampleController();
6666

67-
// Vary injection based on zend-servicemanager version
68-
if (method_exists($this->controllers, 'configure')) {
69-
// v3
70-
$this->controllers->injectEventManager($this->services, $controller);
71-
} else {
72-
// v2
73-
$this->controllers->injectEventManager($controller, $this->controllers);
74-
}
67+
$this->controllers->injectEventManager($this->services, $controller);
7568

7669
// The default AbstractController implementation lazy instantiates an EM
7770
// instance, which means we need to check that that instance gets injected
@@ -85,14 +78,7 @@ public function testCanInjectPluginManager()
8578
{
8679
$controller = new TestAsset\SampleController();
8780

88-
// Vary injection based on zend-servicemanager version
89-
if (method_exists($this->controllers, 'configure')) {
90-
// v3
91-
$this->controllers->injectPluginManager($this->services, $controller);
92-
} else {
93-
// v2
94-
$this->controllers->injectPluginManager($controller, $this->controllers);
95-
}
81+
$this->controllers->injectPluginManager($this->services, $controller);
9682

9783
$this->assertSame($this->services->get('ControllerPluginManager'), $controller->getPluginManager());
9884
}
@@ -103,14 +89,7 @@ public function testInjectEventManagerWillNotOverwriteExistingEventManagerIfItAl
10389
$controller = new TestAsset\SampleController();
10490
$controller->setEventManager($events);
10591

106-
// Vary injection based on zend-servicemanager version
107-
if (method_exists($this->controllers, 'configure')) {
108-
// v3
109-
$this->controllers->injectEventManager($this->services, $controller);
110-
} else {
111-
// v2
112-
$this->controllers->injectEventManager($controller, $this->controllers);
113-
}
92+
$this->controllers->injectEventManager($this->services, $controller);
11493

11594
$this->assertSame($events, $controller->getEventManager());
11695
$this->assertSame($this->sharedEvents, $events->getSharedManager());

test/Controller/Plugin/ForwardTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,19 @@
1414
use stdClass;
1515
use Zend\EventManager\EventManager;
1616
use Zend\EventManager\SharedEventManager;
17+
use Zend\EventManager\SharedEventManagerInterface;
1718
use Zend\Http\Request;
1819
use Zend\Http\Response;
1920
use Zend\Mvc\Controller\ControllerManager;
20-
use Zend\Mvc\Controller\PluginManager;
21+
use Zend\Mvc\Controller\Plugin\Forward;
2122
use Zend\Mvc\Controller\Plugin\Forward as ForwardPlugin;
23+
use Zend\Mvc\Controller\PluginManager;
24+
use Zend\Mvc\Exception\DomainException;
2225
use Zend\Mvc\MvcEvent;
2326
use Zend\Router\RouteMatch;
2427
use Zend\ServiceManager\Config;
28+
use Zend\ServiceManager\Exception\InvalidServiceException;
29+
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
2530
use Zend\ServiceManager\ServiceManager;
2631
use ZendTest\Mvc\Controller\TestAsset\ForwardController;
2732
use ZendTest\Mvc\Controller\TestAsset\SampleController;
@@ -45,7 +50,7 @@ class ForwardTest extends TestCase
4550
private $controller;
4651

4752
/**
48-
* @var \Zend\Mvc\Controller\Plugin\Forward
53+
* @var Forward
4954
*/
5055
private $plugin;
5156

@@ -131,14 +136,14 @@ public function testPluginWithoutEventAwareControllerRaisesDomainException()
131136
$controller = new UneventfulController();
132137
$plugin = new ForwardPlugin($this->controllers);
133138
$plugin->setController($controller);
134-
$this->setExpectedException('Zend\Mvc\Exception\DomainException', 'InjectApplicationEventInterface');
139+
$this->setExpectedException(DomainException::class, 'InjectApplicationEventInterface');
135140
$plugin->dispatch('forward');
136141
}
137142

138143
public function testPluginWithoutControllerLocatorRaisesServiceNotCreatedException()
139144
{
140145
$controller = new SampleController();
141-
$this->setExpectedException('Zend\ServiceManager\Exception\ServiceNotCreatedException');
146+
$this->setExpectedException(ServiceNotCreatedException::class);
142147
$plugin = $controller->plugin('forward');
143148
}
144149

@@ -150,12 +155,7 @@ public function testDispatchRaisesDomainExceptionIfDiscoveredControllerIsNotDisp
150155
$plugin = new ForwardPlugin($this->controllers);
151156
$plugin->setController($this->controller);
152157

153-
// Vary exception expected based on zend-servicemanager version
154-
$expectedException = method_exists($this->controllers, 'configure')
155-
? 'Zend\ServiceManager\Exception\InvalidServiceException' // v3
156-
: 'Zend\Mvc\Exception\InvalidControllerException'; // v2
157-
158-
$this->setExpectedException($expectedException, 'DispatchableInterface');
158+
$this->setExpectedException(InvalidServiceException::class, 'DispatchableInterface');
159159
$plugin->dispatch('bogus');
160160
}
161161

@@ -207,7 +207,7 @@ public function testDispatchRaisesDomainExceptionIfCircular()
207207
$forward = new ForwardPlugin($controllers);
208208
$forward->setController($controllers->get('sample'));
209209

210-
$this->setExpectedException('Zend\Mvc\Exception\DomainException', 'Circular forwarding');
210+
$this->setExpectedException(DomainException::class, 'Circular forwarding');
211211
$forward->dispatch('sample', ['action' => 'test-circular']);
212212
}
213213

@@ -225,7 +225,7 @@ public function testNonArrayListenerDoesNotRaiseErrorWhenPluginDispatchsRequeste
225225
{
226226
$services = $this->services;
227227
$events = $services->get('EventManager');
228-
$sharedEvents = $this->getMock('Zend\EventManager\SharedEventManagerInterface');
228+
$sharedEvents = $this->getMock(SharedEventManagerInterface::class);
229229
// @codingStandardsIgnoreStart
230230
$sharedEvents->expects($this->any())->method('getListeners')->will($this->returnValue([
231231
function ($e) {}

test/Controller/Plugin/TestAsset/SamplePluginFactory.php

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,12 @@
1010
namespace ZendTest\Mvc\Controller\Plugin\TestAsset;
1111

1212
use Interop\Container\ContainerInterface;
13-
use Zend\ServiceManager\FactoryInterface;
14-
use Zend\ServiceManager\ServiceLocatorInterface;
13+
use Zend\ServiceManager\Factory\FactoryInterface;
1514

1615
class SamplePluginFactory implements FactoryInterface
1716
{
1817
public function __invoke(ContainerInterface $container, $name, array $options = null)
1918
{
2019
return new SamplePlugin();
2120
}
22-
23-
/**
24-
* Create and return SamplePlugin instance
25-
*
26-
* For use with zend-servicemanager v2; proxies to __invoke().
27-
*
28-
* @param ServiceLocatorInterface $container
29-
* @return SamplePlugin
30-
*/
31-
public function createService(ServiceLocatorInterface $container)
32-
{
33-
return $this($container, SamplePlugin::class);
34-
}
3521
}

test/Controller/Plugin/TestAsset/SamplePluginWithConstructorFactory.php

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
namespace ZendTest\Mvc\Controller\Plugin\TestAsset;
1111

1212
use Interop\Container\ContainerInterface;
13-
use Zend\ServiceManager\FactoryInterface;
14-
use Zend\ServiceManager\ServiceLocatorInterface;
13+
use Zend\ServiceManager\Factory\FactoryInterface;
1514

1615
class SamplePluginWithConstructorFactory implements FactoryInterface
1716
{
@@ -22,20 +21,6 @@ public function __invoke(ContainerInterface $container, $name, array $options =
2221
return new SamplePluginWithConstructor($options);
2322
}
2423

25-
/**
26-
* Create and return SamplePluginWithConstructor instance
27-
*
28-
* For use with zend-servicemanager v2; proxies to __invoke().
29-
*
30-
* @param ServiceLocatorInterface $container
31-
* @return SamplePluginWithConstructor
32-
*/
33-
public function createService(ServiceLocatorInterface $container)
34-
{
35-
$container = $container->getServiceLocator() ?: $container;
36-
return $this($container, SamplePluginWithConstructor::class, $this->options);
37-
}
38-
3924
public function setCreationOptions(array $options)
4025
{
4126
$this->options = $options;

test/Controller/TestAsset/ControllerLoaderAbstractFactory.php

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
namespace ZendTest\Mvc\Controller\TestAsset;
1111

1212
use Interop\Container\ContainerInterface;
13-
use Zend\ServiceManager\AbstractFactoryInterface;
14-
use Zend\ServiceManager\ServiceLocatorInterface;
13+
use Zend\ServiceManager\Factory\AbstractFactoryInterface;
1514

1615
class ControllerLoaderAbstractFactory implements AbstractFactoryInterface
1716
{
@@ -29,28 +28,9 @@ public function canCreate(ContainerInterface $container, $name)
2928
return class_exists($classname);
3029
}
3130

32-
public function canCreateServiceWithName(ServiceLocatorInterface $container, $normalizedName, $name)
33-
{
34-
return $this->canCreate($container, $name);
35-
}
36-
3731
public function __invoke(ContainerInterface $container, $name, array $options = null)
3832
{
3933
$classname = $this->classmap[$name];
4034
return new $classname;
4135
}
42-
43-
/**
44-
* Create and return DispatchableInterface instance
45-
*
46-
* For use with zend-servicemanager v2; proxies to __invoke().
47-
*
48-
* {@inheritDoc}
49-
*
50-
* @return DispatchableInterface
51-
*/
52-
public function createServiceWithName(ServiceLocatorInterface $container, $name, $requestedName)
53-
{
54-
return $this($container, $requestedName);
55-
}
5636
}

test/Controller/TestAsset/UnlocatableControllerLoaderAbstractFactory.php

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
namespace ZendTest\Mvc\Controller\TestAsset;
1111

1212
use Interop\Container\ContainerInterface;
13-
use Zend\ServiceManager\AbstractFactoryInterface;
14-
use Zend\ServiceManager\ServiceLocatorInterface;
13+
use Zend\ServiceManager\Factory\AbstractFactoryInterface;
1514

1615
class UnlocatableControllerLoaderAbstractFactory implements AbstractFactoryInterface
1716
{
@@ -20,21 +19,7 @@ public function canCreate(ContainerInterface $container, $name)
2019
return false;
2120
}
2221

23-
/**
24-
* {@inheritDoc}
25-
*
26-
* For use with zend-servicemanager v2; proxies to canCreate().
27-
*/
28-
public function canCreateServiceWithName(ServiceLocatorInterface $container, $name, $requestedName)
29-
{
30-
return $this->canCreate($container, $requestedName);
31-
}
32-
3322
public function __invoke(ContainerInterface $container, $name, array $options = null)
3423
{
3524
}
36-
37-
public function createServiceWithName(ServiceLocatorInterface $container, $name, $requestedName)
38-
{
39-
}
4025
}

0 commit comments

Comments
 (0)