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

Fix 'Call to a member function hasChildren() on boolean' #26

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/View/Console/DefaultRenderingStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -42,7 +43,7 @@ public function render(MvcEvent $e)
// marshal arguments
$response = $e->getResponse();

if (empty($result)) {
if (empty($result) || !($result instanceof ModelInterface)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can simply remove the empty() call

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except this comment, all of your other comments relate to the existing test code that I copied. So I'll apply your suggestions to both tests - I was just following what was already there :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@skl thanks!

// There is absolutely no result, so there's nothing to display.
// We will return an empty response object
return $response;
Expand Down
31 changes: 31 additions & 0 deletions test/View/Console/DefaultRenderingStrategyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,35 @@ public function testIgnoresNonConsoleModelNotContainingResultKeyWhenObtainingRes
$content = $response->getContent();
$this->assertNotContains('Page not found', $content);
}

public function testIgnoresNonModel()
{
$console = $this->getMock('Zend\Console\Adapter\AbstractAdapter');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

::class please :-)

$console
->expects($this->any())
->method('encodeText')
->willReturnArgument(0)
;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Semicolon on the previous line


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

/** @var \PHPUnit_Framework_MockObject_MockObject|\Zend\Mvc\ApplicationInterface $mockApplication */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IDE hints should use /*, not /** (docblock)

$mockApplication = $this->getMock('Zend\Mvc\ApplicationInterface');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

::class please :-)

$mockApplication
->expects($this->any())
->method('getServiceManager')
->willReturn($sm)
;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Semicolon on the previous line

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have CS guidelines about the placement of the trailing semicolon on a method chain

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, nothing came up when I ran cs fixer either.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No strong feelings on it, I guess we'll eventually add the rule later on, if this keeps popping up


$event = new MvcEvent();
$event->setApplication($mockApplication);

$model = true;
$response = new Response();
$event->setResult($model);
$event->setResponse($response);
$this->assertSame($response, $this->strategy->render($event));
}
}