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

Commit

Permalink
Merge branch 'hotfix/send-response-factory'
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Aug 29, 2016
2 parents 75d3672 + d5539da commit 69ac3e4
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 3 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

All notable changes to this project will be documented in this file, in reverse chronological order by release.

## 3.0.3 - TBD
## 3.0.3 - 2016-08-29

### Added

- Nothing.
- [#198](https://github.com/zendframework/zend-mvc/pull/198) adds a factory for
the `SendResponseListener`, to ensure that it is injected with an event
manager instance from the outset; this fixes issues with delegator factories
that registered listeners with it in previous versions.

### Deprecated

Expand Down
25 changes: 25 additions & 0 deletions src/Service/SendResponseListenerFactory.php
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;
}
}
2 changes: 1 addition & 1 deletion src/Service/ServiceListenerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class ServiceListenerFactory implements FactoryInterface
'ViewPrefixPathStackResolver' => 'Zend\Mvc\Service\ViewPrefixPathStackResolverFactory',
'Zend\Mvc\MiddlewareListener' => InvokableFactory::class,
'Zend\Mvc\RouteListener' => InvokableFactory::class,
'Zend\Mvc\SendResponseListener' => InvokableFactory::class,
'Zend\Mvc\SendResponseListener' => SendResponseListenerFactory::class,
'Zend\View\Renderer\FeedRenderer' => InvokableFactory::class,
'Zend\View\Renderer\JsonRenderer' => InvokableFactory::class,
'Zend\View\Renderer\PhpRenderer' => ViewPhpRendererFactory::class,
Expand Down
55 changes: 55 additions & 0 deletions test/Service/SendResponseListenerFactoryTest.php
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());
}
}

0 comments on commit 69ac3e4

Please sign in to comment.