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

Commit b44fd52

Browse files
committed
Merge pull request #27 from skl/calling-function-on-boolean
Fix 'Call to a member function hasChildren() on boolean'
2 parents 4a94f57 + a96d349 commit b44fd52

File tree

2 files changed

+41
-8
lines changed

2 files changed

+41
-8
lines changed

src/View/Console/DefaultRenderingStrategy.php

Lines changed: 3 additions & 1 deletion
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.

test/View/Console/DefaultRenderingStrategyTest.php

Lines changed: 38 additions & 7 deletions
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)