Fix documentation and add tests for BaseRoute
This commit is contained in:
parent
e597926634
commit
6a642dfed2
|
|
@ -1,5 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* pjdietz\WellRESTed\BaseRoute
|
||||||
|
*
|
||||||
|
* @author PJ Dietz <pj@pjdietz.com>
|
||||||
|
* @copyright Copyright 2014 by PJ Dietz
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
namespace pjdietz\WellRESTed\Routes;
|
namespace pjdietz\WellRESTed\Routes;
|
||||||
|
|
||||||
use pjdietz\WellRESTed\Interfaces\HandlerInterface;
|
use pjdietz\WellRESTed\Interfaces\HandlerInterface;
|
||||||
|
|
@ -9,14 +17,16 @@ use pjdietz\WellRESTed\Interfaces\HandlerInterface;
|
||||||
*/
|
*/
|
||||||
abstract class BaseRoute implements HandlerInterface
|
abstract class BaseRoute implements HandlerInterface
|
||||||
{
|
{
|
||||||
/** @var string Fully qualified name for the interface for handlers */
|
/** @var string Fully qualified name for the interface for handlers */
|
||||||
const HANDLER_INTERFACE = '\\pjdietz\\WellRESTed\\Interfaces\\HandlerInterface';
|
const HANDLER_INTERFACE = '\\pjdietz\\WellRESTed\\Interfaces\\HandlerInterface';
|
||||||
|
|
||||||
/** @var string */
|
/** @var string Fully qualified classname of the HandlerInterface to dispatch*/
|
||||||
private $targetClassName;
|
private $targetClassName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $targetClassName Fully qualified name to an autoloadable handler class.
|
* Create a new route that will dispatch an instance of the given handelr class.
|
||||||
|
*
|
||||||
|
* @param string $targetClassName Fully qualified name to a handler class.
|
||||||
*/
|
*/
|
||||||
public function __construct($targetClassName)
|
public function __construct($targetClassName)
|
||||||
{
|
{
|
||||||
|
|
@ -24,8 +34,10 @@ abstract class BaseRoute implements HandlerInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return HandlerInterface
|
* Instantiate and return an instance of the assigned HandlerInterface
|
||||||
|
*
|
||||||
* @throws \UnexpectedValueException
|
* @throws \UnexpectedValueException
|
||||||
|
* @return HandlerInterface
|
||||||
*/
|
*/
|
||||||
protected function getTarget()
|
protected function getTarget()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace pjdietz\WellRESTed\Test;
|
||||||
|
|
||||||
|
use pjdietz\WellRESTed\Routes\StaticRoute;
|
||||||
|
|
||||||
|
class BaseRouteTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Create a route that will match, but has an incorrect handler assigned.
|
||||||
|
* @expectedException \UnexpectedValueException
|
||||||
|
*/
|
||||||
|
public function testSinglePathMatch()
|
||||||
|
{
|
||||||
|
$path = "/";
|
||||||
|
|
||||||
|
$mockRequest = $this->getMock('\pjdietz\WellRESTed\Interfaces\RequestInterface');
|
||||||
|
$mockRequest->expects($this->any())
|
||||||
|
->method('getPath')
|
||||||
|
->will($this->returnValue($path));
|
||||||
|
|
||||||
|
$path = "/";
|
||||||
|
$route = new StaticRoute($path, __NAMESPACE__ . '\NotAHandler');
|
||||||
|
$resp = $route->getResponse($mockRequest);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class NotAHandler
|
||||||
|
{
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue