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

Commit 076b0c8

Browse files
committed
Merge branch 'hotfix/27'
Close #27
2 parents 4a94f57 + b1fc7ca commit 076b0c8

File tree

3 files changed

+64
-8
lines changed

3 files changed

+64
-8
lines changed

Diff for: CHANGELOG.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file, in reverse chronological order by release.
4+
5+
## 2.5.2 - 2015-09-14
6+
7+
### Added
8+
9+
- Nothing.
10+
11+
### Deprecated
12+
13+
- Nothing.
14+
15+
### Removed
16+
17+
- Nothing.
18+
19+
### Fixed
20+
21+
- [#27](https://github.com/zendframework/zend-mvc/pull/27) fixes a condition
22+
where non-view model results from controllers could cause errors to be
23+
raisedin the `DefaultRenderingStrategy`.

Diff for: src/View/Console/DefaultRenderingStrategy.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Zend\Mvc\MvcEvent;
1616
use Zend\Stdlib\ResponseInterface as Response;
1717
use Zend\View\Model\ConsoleModel as ConsoleViewModel;
18+
use Zend\View\Model\ModelInterface;
1819

1920
class DefaultRenderingStrategy extends AbstractListenerAggregate
2021
{
@@ -42,7 +43,7 @@ public function render(MvcEvent $e)
4243
// marshal arguments
4344
$response = $e->getResponse();
4445

45-
if (empty($result)) {
46+
if (!$result instanceof ModelInterface) {
4647
// There is absolutely no result, so there's nothing to display.
4748
// We will return an empty response object
4849
return $response;
@@ -51,6 +52,7 @@ public function render(MvcEvent $e)
5152
// Collect results from child models
5253
$responseText = '';
5354
if ($result->hasChildren()) {
55+
/* @var ModelInterface $child */
5456
foreach ($result->getChildren() as $child) {
5557
// Do not use ::getResult() method here as we cannot be sure if
5658
// children are also console models.

Diff for: test/View/Console/DefaultRenderingStrategyTest.php

+38-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
namespace ZendTest\Mvc\View\Console;
1111

1212
use PHPUnit_Framework_TestCase as TestCase;
13+
use Zend\Console\Adapter\AbstractAdapter;
1314
use Zend\EventManager\EventManager;
15+
use Zend\Mvc\ApplicationInterface;
1416
use Zend\Mvc\MvcEvent;
1517
use Zend\Mvc\View\Console\DefaultRenderingStrategy;
1618
use Zend\ServiceManager\ServiceManager;
@@ -36,6 +38,8 @@ public function testAttachesRendererAtExpectedPriority()
3638
$expectedCallback = [$this->strategy, 'render'];
3739
$expectedPriority = -10000;
3840
$found = false;
41+
42+
/* @var \Zend\Stdlib\CallbackHandler $listener */
3943
foreach ($listeners as $listener) {
4044
$callback = $listener->getCallback();
4145
if ($callback === $expectedCallback) {
@@ -60,24 +64,22 @@ public function testCanDetachListenersFromEventManager()
6064

6165
public function testIgnoresNonConsoleModelNotContainingResultKeyWhenObtainingResult()
6266
{
63-
$console = $this->getMock('Zend\Console\Adapter\AbstractAdapter');
67+
$console = $this->getMock(AbstractAdapter::class);
6468
$console
6569
->expects($this->any())
6670
->method('encodeText')
67-
->willReturnArgument(0)
68-
;
71+
->willReturnArgument(0);
6972

7073
//Register console service
7174
$sm = new ServiceManager();
7275
$sm->setService('console', $console);
7376

74-
/** @var \PHPUnit_Framework_MockObject_MockObject|\Zend\Mvc\ApplicationInterface $mockApplication */
75-
$mockApplication = $this->getMock('Zend\Mvc\ApplicationInterface');
77+
/* @var \PHPUnit_Framework_MockObject_MockObject|ApplicationInterface $mockApplication */
78+
$mockApplication = $this->getMock(ApplicationInterface::class);
7679
$mockApplication
7780
->expects($this->any())
7881
->method('getServiceManager')
79-
->willReturn($sm)
80-
;
82+
->willReturn($sm);
8183

8284
$event = new MvcEvent();
8385
$event->setApplication($mockApplication);
@@ -90,4 +92,33 @@ public function testIgnoresNonConsoleModelNotContainingResultKeyWhenObtainingRes
9092
$content = $response->getContent();
9193
$this->assertNotContains('Page not found', $content);
9294
}
95+
96+
public function testIgnoresNonModel()
97+
{
98+
$console = $this->getMock(AbstractAdapter::class);
99+
$console
100+
->expects($this->any())
101+
->method('encodeText')
102+
->willReturnArgument(0);
103+
104+
//Register console service
105+
$sm = new ServiceManager();
106+
$sm->setService('console', $console);
107+
108+
/* @var \PHPUnit_Framework_MockObject_MockObject|ApplicationInterface $mockApplication */
109+
$mockApplication = $this->getMock(ApplicationInterface::class);
110+
$mockApplication
111+
->expects($this->any())
112+
->method('getServiceManager')
113+
->willReturn($sm);
114+
115+
$event = new MvcEvent();
116+
$event->setApplication($mockApplication);
117+
118+
$model = true;
119+
$response = new Response();
120+
$event->setResult($model);
121+
$event->setResponse($response);
122+
$this->assertSame($response, $this->strategy->render($event));
123+
}
93124
}

0 commit comments

Comments
 (0)