Skip to content

Commit

Permalink
Update Controller::redirect() as well.
Browse files Browse the repository at this point in the history
In addition to the Controller method, fixup the Stub\Response to work
better with PSR7 responses. By returning $this, we can start using
immutable methods and not adversely effect tests. Without this if people
used immutable methods their tests would start failing.
  • Loading branch information
markstory committed Oct 27, 2016
1 parent 549cb20 commit 24294fa
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Controller/Controller.php
Expand Up @@ -540,7 +540,7 @@ public function redirect($url, $status = 302)

$response = $this->response;
if ($status) {
$response->statusCode($status);
$response = $response->withStatus($status);
}

$event = $this->dispatchEvent('Controller.beforeRedirect', [$url, $response]);
Expand Down
4 changes: 1 addition & 3 deletions src/TestSuite/LegacyRequestDispatcher.php
Expand Up @@ -51,8 +51,6 @@ public function execute($request)
['priority' => 999],
[$this->_test, 'controllerSpy']
);
$dispatcher->dispatch($request, $response);

return $response;
return $dispatcher->dispatch($request, $response);
}
}
3 changes: 2 additions & 1 deletion src/TestSuite/Stub/Response.php
Expand Up @@ -24,13 +24,14 @@ class Response extends Base
/**
* Stub the send() method so headers and output are not sent.
*
* @return void
* @return $this
*/
public function send()
{
if (isset($this->_headers['Location']) && $this->_status === 200) {
$this->statusCode(302);
}
$this->_setContentType();
return $this;
}
}

0 comments on commit 24294fa

Please sign in to comment.