diff --git a/src/View/Console/DefaultRenderingStrategy.php b/src/View/Console/DefaultRenderingStrategy.php index cb15f4747..f32f3f98e 100644 --- a/src/View/Console/DefaultRenderingStrategy.php +++ b/src/View/Console/DefaultRenderingStrategy.php @@ -15,6 +15,7 @@ use Zend\Mvc\MvcEvent; use Zend\Stdlib\ResponseInterface as Response; use Zend\View\Model\ConsoleModel as ConsoleViewModel; +use Zend\View\Model\ModelInterface; class DefaultRenderingStrategy extends AbstractListenerAggregate { @@ -42,7 +43,7 @@ public function render(MvcEvent $e) // marshal arguments $response = $e->getResponse(); - if (empty($result)) { + if (!$result instanceof ModelInterface) { // There is absolutely no result, so there's nothing to display. // We will return an empty response object return $response; @@ -51,6 +52,7 @@ public function render(MvcEvent $e) // Collect results from child models $responseText = ''; if ($result->hasChildren()) { + /* @var ModelInterface $child */ foreach ($result->getChildren() as $child) { // Do not use ::getResult() method here as we cannot be sure if // children are also console models. diff --git a/test/View/Console/DefaultRenderingStrategyTest.php b/test/View/Console/DefaultRenderingStrategyTest.php index d02dbdeff..f932d838f 100644 --- a/test/View/Console/DefaultRenderingStrategyTest.php +++ b/test/View/Console/DefaultRenderingStrategyTest.php @@ -10,7 +10,9 @@ namespace ZendTest\Mvc\View\Console; use PHPUnit_Framework_TestCase as TestCase; +use Zend\Console\Adapter\AbstractAdapter; use Zend\EventManager\EventManager; +use Zend\Mvc\ApplicationInterface; use Zend\Mvc\MvcEvent; use Zend\Mvc\View\Console\DefaultRenderingStrategy; use Zend\ServiceManager\ServiceManager; @@ -36,6 +38,8 @@ public function testAttachesRendererAtExpectedPriority() $expectedCallback = [$this->strategy, 'render']; $expectedPriority = -10000; $found = false; + + /* @var \Zend\Stdlib\CallbackHandler $listener */ foreach ($listeners as $listener) { $callback = $listener->getCallback(); if ($callback === $expectedCallback) { @@ -60,24 +64,22 @@ public function testCanDetachListenersFromEventManager() public function testIgnoresNonConsoleModelNotContainingResultKeyWhenObtainingResult() { - $console = $this->getMock('Zend\Console\Adapter\AbstractAdapter'); + $console = $this->getMock(AbstractAdapter::class); $console ->expects($this->any()) ->method('encodeText') - ->willReturnArgument(0) - ; + ->willReturnArgument(0); //Register console service $sm = new ServiceManager(); $sm->setService('console', $console); - /** @var \PHPUnit_Framework_MockObject_MockObject|\Zend\Mvc\ApplicationInterface $mockApplication */ - $mockApplication = $this->getMock('Zend\Mvc\ApplicationInterface'); + /* @var \PHPUnit_Framework_MockObject_MockObject|ApplicationInterface $mockApplication */ + $mockApplication = $this->getMock(ApplicationInterface::class); $mockApplication ->expects($this->any()) ->method('getServiceManager') - ->willReturn($sm) - ; + ->willReturn($sm); $event = new MvcEvent(); $event->setApplication($mockApplication); @@ -90,4 +92,33 @@ public function testIgnoresNonConsoleModelNotContainingResultKeyWhenObtainingRes $content = $response->getContent(); $this->assertNotContains('Page not found', $content); } + + public function testIgnoresNonModel() + { + $console = $this->getMock(AbstractAdapter::class); + $console + ->expects($this->any()) + ->method('encodeText') + ->willReturnArgument(0); + + //Register console service + $sm = new ServiceManager(); + $sm->setService('console', $console); + + /* @var \PHPUnit_Framework_MockObject_MockObject|ApplicationInterface $mockApplication */ + $mockApplication = $this->getMock(ApplicationInterface::class); + $mockApplication + ->expects($this->any()) + ->method('getServiceManager') + ->willReturn($sm); + + $event = new MvcEvent(); + $event->setApplication($mockApplication); + + $model = true; + $response = new Response(); + $event->setResult($model); + $event->setResponse($response); + $this->assertSame($response, $this->strategy->render($event)); + } }