This repository has been archived by the owner on Jan 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'hotfix/send-response-factory'
Close #198 Fixes zendframework/zend-mvc-console#10 Fixes zendframework/zend-mvc-console#11 Fixes zendframework/zend-mvc-console#12
- Loading branch information
Showing
4 changed files
with
86 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
/** | ||
* @link http://github.com/zendframework/zend-mvc for the canonical source repository | ||
* @copyright Copyright (c) 2016 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
namespace Zend\Mvc\Service; | ||
|
||
use Interop\Container\ContainerInterface; | ||
use Zend\Mvc\SendResponseListener; | ||
|
||
class SendResponseListenerFactory | ||
{ | ||
/** | ||
* @param ContainerInterface $container | ||
* @return SendResponseListener | ||
*/ | ||
public function __invoke(ContainerInterface $container) | ||
{ | ||
$listener = new SendResponseListener(); | ||
$listener->setEventManager($container->get('EventManager')); | ||
return $listener; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
/** | ||
* @link http://github.com/zendframework/zend-mvc for the canonical source repository | ||
* @copyright Copyright (c) 2016 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
namespace ZendTest\Mvc\Service; | ||
|
||
use Interop\Container\ContainerInterface; | ||
use PHPUnit_Framework_TestCase as TestCase; | ||
use Prophecy\Argument; | ||
use Zend\EventManager\EventManagerInterface; | ||
use Zend\EventManager\SharedEventManagerInterface; | ||
use Zend\Mvc\ResponseSender\HttpResponseSender; | ||
use Zend\Mvc\ResponseSender\PhpEnvironmentResponseSender; | ||
use Zend\Mvc\ResponseSender\SendResponseEvent; | ||
use Zend\Mvc\ResponseSender\SimpleStreamResponseSender; | ||
use Zend\Mvc\SendResponseListener; | ||
use Zend\Mvc\Service\SendResponseListenerFactory; | ||
|
||
class SendResponseListenerFactoryTest extends TestCase | ||
{ | ||
public function testFactoryReturnsListenerWithEventManagerFromContainer() | ||
{ | ||
$sharedEvents = $this->prophesize(SharedEventManagerInterface::class); | ||
$events = $this->prophesize(EventManagerInterface::class); | ||
$events->getSharedManager()->will([$sharedEvents, 'reveal']); | ||
|
||
$events->setIdentifiers([SendResponseListener::class, SendResponseListener::class])->shouldBeCalled(); | ||
$events->attach( | ||
SendResponseEvent::EVENT_SEND_RESPONSE, | ||
Argument::type(PhpEnvironmentResponseSender::class), | ||
-1000 | ||
)->shouldBeCalled(); | ||
$events->attach( | ||
SendResponseEvent::EVENT_SEND_RESPONSE, | ||
Argument::type(SimpleStreamResponseSender::class), | ||
-3000 | ||
)->shouldBeCalled(); | ||
$events->attach( | ||
SendResponseEvent::EVENT_SEND_RESPONSE, | ||
Argument::type(HttpResponseSender::class), | ||
-4000 | ||
)->shouldBeCalled(); | ||
|
||
$container = $this->prophesize(ContainerInterface::class); | ||
$container->get('EventManager')->will([$events, 'reveal']); | ||
|
||
$factory = new SendResponseListenerFactory(); | ||
$listener = $factory($container->reveal()); | ||
$this->assertInstanceOf(SendResponseListener::class, $listener); | ||
$this->assertSame($events->reveal(), $listener->getEventManager()); | ||
} | ||
} |