Revise DispatchterTest

This commit is contained in:
PJ Dietz 2015-05-07 07:38:32 -04:00
parent ec7dceac98
commit 7cbbe6d7c5
1 changed files with 32 additions and 19 deletions

View File

@ -20,51 +20,64 @@ class DispatcherTest extends \PHPUnit_Framework_TestCase
{ {
$this->request = $this->prophesize("\\Psr\\Http\\Message\\ServerRequestInterface"); $this->request = $this->prophesize("\\Psr\\Http\\Message\\ServerRequestInterface");
$this->response = $this->prophesize("\\Psr\\Http\\Message\\ResponseInterface"); $this->response = $this->prophesize("\\Psr\\Http\\Message\\ResponseInterface");
$this->response->withStatus(Argument::any())->willReturn($this->response->reveal()); $this->response->withStatus(Argument::any())->will(
function ($args) {
$this->getStatusCode()->willReturn($args[0]);
return $this;
}
);
} }
public function testDispatchedCallable() public function testDispatchesCallable()
{ {
$middleware = function ($request, &$response) { $middleware = function ($request, &$response) {
$response = $response->withStatus(200); $response = $response->withStatus(200);
}; };
$dispatcher = new Dispatcher(); $dispatcher = new Dispatcher();
$request = $this->request->reveal();
$response = $this->response->reveal(); $response = $this->response->reveal();
$dispatcher->dispatch($middleware, $this->request->reveal(), $response); $dispatcher->dispatch($middleware, $request, $response);
$this->response->withStatus(200)->shouldHaveBeenCalled();
$this->assertSame($this->response->reveal(), $response); $this->assertEquals(200, $response->getStatusCode());
} }
public function testDispatchedFromCallable() public function testDispatchesMiddlewareInstanceFromCallable()
{ {
$middleware = function () { $middleware = function () {
return new DispatcherTest_Middleware(); return new DispatcherTest_Middleware();
}; };
$response = $this->response->reveal();
$dispatcher = new Dispatcher(); $dispatcher = new Dispatcher();
$dispatcher->dispatch($middleware, $this->request->reveal(), $response); $request = $this->request->reveal();
$this->response->withStatus(200)->shouldHaveBeenCalled(); $response = $this->response->reveal();
$this->assertSame($this->response->reveal(), $response); $dispatcher->dispatch($middleware, $request, $response);
$this->assertEquals(200, $response->getStatusCode());
} }
public function testDispatchedFromString() public function testDispatchesMiddlewareFromClassNameString()
{ {
$middleware = __NAMESPACE__ . "\\DispatcherTest_Middleware"; $middleware = __NAMESPACE__ . "\\DispatcherTest_Middleware";
$response = $this->response->reveal();
$dispatcher = new Dispatcher(); $dispatcher = new Dispatcher();
$dispatcher->dispatch($middleware, $this->request->reveal(), $response); $request = $this->request->reveal();
$this->response->withStatus(200)->shouldHaveBeenCalled(); $response = $this->response->reveal();
$this->assertSame($this->response->reveal(), $response); $dispatcher->dispatch($middleware, $request, $response);
$this->assertEquals(200, $response->getStatusCode());
} }
public function testDispatchedInstance() public function testDispatchesMiddlewareInstance()
{ {
$middleware = new DispatcherTest_Middleware(); $middleware = new DispatcherTest_Middleware();
$dispatcher = new Dispatcher(); $dispatcher = new Dispatcher();
$request = $this->request->reveal();
$response = $this->response->reveal(); $response = $this->response->reveal();
$dispatcher->dispatch($middleware, $this->request->reveal(), $response); $dispatcher->dispatch($middleware, $request, $response);
$this->response->withStatus(200)->shouldHaveBeenCalled();
$this->assertSame($this->response->reveal(), $response); $this->assertEquals(200, $response->getStatusCode());
} }
} }