summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorArnold Daniels <arnold@jasny.net>2016-10-30 11:28:54 +0100
committerArnold Daniels <arnold@jasny.net>2016-10-30 11:28:54 +0100
commitf7135f61882288f45afaeea9efdd5ea8b248de91 (patch)
treecf5f7ac9f5df4e02496aded2901b77f6e0c5440d /tests
parent780a4648b1e2eac3fcf8b7831807529d1455e647 (diff)
downloadrouter-f7135f61882288f45afaeea9efdd5ea8b248de91.zip
router-f7135f61882288f45afaeea9efdd5ea8b248de91.tar.gz
router-f7135f61882288f45afaeea9efdd5ea8b248de91.tar.bz2
Error handler has moved to it's own library
Diffstat (limited to 'tests')
-rw-r--r--tests/Router/Middleware/ErrorHandlerTest.php86
-rw-r--r--tests/support/TestHelpers.php3
2 files changed, 2 insertions, 87 deletions
diff --git a/tests/Router/Middleware/ErrorHandlerTest.php b/tests/Router/Middleware/ErrorHandlerTest.php
deleted file mode 100644
index c4b6313..0000000
--- a/tests/Router/Middleware/ErrorHandlerTest.php
+++ /dev/null
@@ -1,86 +0,0 @@
-<?php
-
-use Jasny\Router\Middleware\ErrorHandler;
-use Psr\Http\Message\ServerRequestInterface;
-use Psr\Http\Message\ResponseInterface;
-use Psr\Http\Message\StreamInterface;
-
-class ErrorHandlerTest extends PHPUnit_Framework_TestCase
-{
- /**
- * Test invoke with invalid 'next' param
- */
- public function testInvokeInvalidNext()
- {
- $middleware = new ErrorHandler();
- list($request, $response) = $this->getRequests();
-
- $this->expectException(\InvalidArgumentException::class);
-
- $result = $middleware($request, $response, 'not_callable');
- }
-
- /**
- * Test that exception in 'next' callback is caught
- */
- public function testInvokeCatchError()
- {
- $middleware = new ErrorHandler();
- list($request, $response) = $this->getRequests();
-
- $this->expectCatchError($response);
-
- $result = $middleware($request, $response, function($request, $response) {
- throw new Exception('Test exception');
- });
-
- $this->assertEquals(get_class($response), get_class($result), "Middleware should return response object");
- }
-
- /**
- * Test case when there is no error
- */
- public function testInvokeNoError()
- {
- $middleware = new ErrorHandler();
- list($request, $response) = $this->getRequests();
-
- $result = $middleware($request, $response, function($request, $response) {
- $response->nextCalled = true;
-
- return $response;
- });
-
- $this->assertEquals(get_class($response), get_class($result), "Middleware should return response object");
- $this->assertTrue($result->nextCalled, "'next' was not called");
- }
-
- /**
- * Get requests for testing
- *
- * @return array
- */
- public function getRequests()
- {
- $request = $this->createMock(ServerRequestInterface::class);
- $response = $this->createMock(ResponseInterface::class);
-
- return [$request, $response];
- }
-
- /**
- * Expect for error
- *
- * @param ResponseInterface $response
- */
- public function expectCatchError($response)
- {
- $stream = $this->createMock(StreamInterface::class);
- $stream->expects($this->once())->method('rewind');
- $stream->expects($this->once())->method('write')->with($this->equalTo('Unexpected error'));
-
- $response->method('getBody')->will($this->returnValue($stream));
- $response->expects($this->once())->method('withBody')->with($this->equalTo($stream))->will($this->returnSelf());
- $response->expects($this->once())->method('withStatus')->with($this->equalTo(500), $this->equalTo('Internal Server Error'))->will($this->returnSelf());
- }
-}
diff --git a/tests/support/TestHelpers.php b/tests/support/TestHelpers.php
index 5604a37..e4fdff7 100644
--- a/tests/support/TestHelpers.php
+++ b/tests/support/TestHelpers.php
@@ -3,6 +3,7 @@
namespace Jasny\Router;
use PHPUnit_Framework_MockObject_Matcher_Invocation as Invocation;
+use PHPUnit_Framework_MockObject_MockObject as MockObject;
/**
* Helper methods for PHPUnit tests
@@ -15,7 +16,7 @@ trait TestHelpers
* @param Invocation $matcher
* @param array $with With arguments
* @param mixed $return
- * @return \PHPUnit_Framework_MockObject_MockObject
+ * @return MockObject
*/
protected function createCallbackMock(Invocation $matcher, $with = [], $return = null)
{