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

Commit

Permalink
Merge pull request #112 from MidnightDesign/php-renderer-strategy-no-…
Browse files Browse the repository at this point in the history
…response

PhpRendererStrategy should be able to handle an event w/o a response
  • Loading branch information
weierophinney committed Mar 20, 2017
2 parents df72b10 + 239eef9 commit 3c2a455
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Strategy/PhpRendererStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ public function selectRenderer(ViewEvent $e)
public function injectResponse(ViewEvent $e)
{
$renderer = $e->getRenderer();
if ($renderer !== $this->renderer) {
$response = $e->getResponse();
if ($renderer !== $this->renderer || $response === null) {
return;
}

$result = $e->getResult();
$response = $e->getResponse();

// Set content
// If content is empty, check common placeholders to determine if they are
Expand Down
13 changes: 13 additions & 0 deletions test/Strategy/PhpRendererStrategyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class PhpRendererStrategyTest extends TestCase
{
use EventListenerIntrospectionTrait;

/** @var PhpRendererStrategy */
private $strategy;

public function setUp()
{
$this->renderer = new PhpRenderer;
Expand Down Expand Up @@ -168,4 +171,14 @@ public function testDetachesListeners()
$listeners = iterator_to_array($this->getListenersForEvent('response', $events));
$this->assertCount(0, $listeners);
}

public function testInjectResponseWorksWithAnEventWithNoResponse()
{
$e = new ViewEvent();
$e->setRenderer($this->strategy->getRenderer());

$this->strategy->injectResponse($e);

$this->assertNull($e->getResponse());
}
}

0 comments on commit 3c2a455

Please sign in to comment.