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

Commit 2b7c7d8

Browse files
committed
Better test case for #11
1 parent e5020aa commit 2b7c7d8

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

test/ServiceManagerTest.php

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
<?php
2-
namespace ZendTest\Mvc\Console;
2+
/**
3+
* @link http://github.com/zendframework/zend-mvc-console for the canonical source repository
4+
* @copyright Copyright (c) 2016 Zend Technologies USA Inc. (http://www.zend.com)
5+
* @license http://framework.zend.com/license/new-bsd New BSD License
6+
*/
37

4-
use PHPUnit_Framework_TestCase as TestCase;
8+
namespace ZendTest\Mvc\Console;
59

610
use Interop\Container\ContainerInterface;
7-
8-
use Zend\ServiceManager\ServiceManager;
9-
use Zend\ServiceManager\Factory\InvokableFactory;
10-
11-
use Zend\Mvc\SendResponseListener;
12-
use Zend\Mvc\Service\ServiceManagerConfig;
13-
11+
use PHPUnit_Framework_TestCase as TestCase;
12+
use Zend\EventManager\Test\EventListenerIntrospectionTrait;
1413
use Zend\Mvc\Console\ResponseSender\ConsoleResponseSender;
1514
use Zend\Mvc\Console\Service\ConsoleResponseSenderDelegatorFactory;
15+
use Zend\Mvc\ResponseSender\SendResponseEvent;
16+
use Zend\Mvc\SendResponseListener;
17+
use Zend\Mvc\Service\ServiceManagerConfig;
18+
use Zend\ServiceManager\ServiceManager;
19+
use Zend\ServiceManager\Factory\InvokableFactory;
1620

1721
use ReflectionProperty;
1822

1923
class ServiceManagerTest extends TestCase
2024
{
25+
use EventListenerIntrospectionTrait;
26+
2127
public function testEventManagerOverridden()
2228
{
2329
$minimalConfig = [
@@ -55,11 +61,19 @@ function (ContainerInterface $container, $name, callable $callback, array $optio
5561

5662
protected function assertEvents($eventManager)
5763
{
58-
$r = new ReflectionProperty($eventManager, 'events');
59-
$r->setAccessible(true);
60-
$events = $r->getValue($eventManager);
64+
$count = 0;
65+
$found = false;
66+
67+
foreach ($this->getListenersForEvent(SendResponseEvent::EVENT_SEND_RESPONSE, $eventManager, true) as $priority => $listener) {
68+
$count++;
69+
if ($priority === -2000
70+
&& $listener instanceof ConsoleResponseSender
71+
) {
72+
$found = true;
73+
}
74+
}
6175

62-
$this->assertEquals(4, count($events['sendResponse']));
63-
$this->assertEquals(ConsoleResponseSender::class, get_class($events['sendResponse']['-2000.0'][0]));
76+
$this->assertEquals(4, $count);
77+
$this->assertTrue($found, 'ConsoleResponseSender was not found in listeners');
6478
}
6579
}

0 commit comments

Comments
 (0)