Update Handler tests

This commit is contained in:
PJ Dietz 2014-07-26 05:20:22 -04:00
parent 4ae6e5f2e4
commit 1222e61ebb
1 changed files with 6 additions and 10 deletions

View File

@ -2,23 +2,23 @@
namespace pjdietz\WellRESTed\Test; namespace pjdietz\WellRESTed\Test;
use pjdietz\WellRESTed\Exceptions\HttpExceptions\HttpException;
use pjdietz\WellRESTed\Exceptions\HttpExceptions\NotFoundException; use pjdietz\WellRESTed\Exceptions\HttpExceptions\NotFoundException;
use pjdietz\WellRESTed\Handler; use pjdietz\WellRESTed\Handler;
class HandlerTest extends \PHPUnit_Framework_TestCase class HandlerTest extends \PHPUnit_Framework_TestCase
{ {
public function testResponse() public function testGetResponse()
{ {
$mockRequest = $this->getMock('\pjdietz\WellRESTed\Interfaces\RequestInterface'); $mockRequest = $this->getMock('\pjdietz\WellRESTed\Interfaces\RequestInterface');
$mockHandler = $this->getMockForAbstractClass('\pjdietz\WellRESTed\Handler'); $mockHandler = $this->getMockForAbstractClass('\pjdietz\WellRESTed\Handler');
/** @var \pjdietz\WellRESTed\Handler $mockHandler */
$this->assertNotNull($mockHandler->getResponse($mockRequest)); $this->assertNotNull($mockHandler->getResponse($mockRequest));
} }
/** /**
* @dataProvider verbProvider * @dataProvider verbProvider
*/ */
public function testVerb($verb) public function testCallMethodForHttpVerb($verb)
{ {
$mockRequest = $this->getMock('\pjdietz\WellRESTed\Interfaces\RequestInterface'); $mockRequest = $this->getMock('\pjdietz\WellRESTed\Interfaces\RequestInterface');
$mockRequest->expects($this->any()) $mockRequest->expects($this->any())
@ -26,6 +26,7 @@ class HandlerTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue($verb)); ->will($this->returnValue($verb));
$mockHandler = $this->getMockForAbstractClass('\pjdietz\WellRESTed\Handler'); $mockHandler = $this->getMockForAbstractClass('\pjdietz\WellRESTed\Handler');
/** @var \pjdietz\WellRESTed\Handler $mockHandler */
$this->assertNotNull($mockHandler->getResponse($mockRequest)); $this->assertNotNull($mockHandler->getResponse($mockRequest));
} }
@ -43,7 +44,7 @@ class HandlerTest extends \PHPUnit_Framework_TestCase
]; ];
} }
public function testHttException() public function testTranslateHttpExceptionToResponse()
{ {
$mockRequest = $this->getMock('\pjdietz\WellRESTed\Interfaces\RequestInterface'); $mockRequest = $this->getMock('\pjdietz\WellRESTed\Interfaces\RequestInterface');
$mockRequest->expects($this->any()) $mockRequest->expects($this->any())
@ -55,18 +56,13 @@ class HandlerTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(404, $resp->getStatusCode()); $this->assertEquals(404, $resp->getStatusCode());
} }
public function testAllowedMethods() public function testReadAllowedMethods()
{ {
$mockRequest = $this->getMock('\pjdietz\WellRESTed\Interfaces\RequestInterface'); $mockRequest = $this->getMock('\pjdietz\WellRESTed\Interfaces\RequestInterface');
$mockRequest->expects($this->any()) $mockRequest->expects($this->any())
->method('getMethod') ->method('getMethod')
->will($this->returnValue("OPTIONS")); ->will($this->returnValue("OPTIONS"));
$mockHandler = $this->getMockForAbstractClass('\pjdietz\WellRESTed\Handler');
$mockHandler->expects($this->any())
->method('getAllowedMethods')
->will($this->returnValue(["GET","POST"]));
$handler = new OptionsHandler(); $handler = new OptionsHandler();
$resp = $handler->getResponse($mockRequest); $resp = $handler->getResponse($mockRequest);