From 09c49802e246f2fe7e326d2afe3dfb832f43738c Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 31 May 2015 16:23:31 -0400 Subject: [PATCH] Introduce FrontController as the replacement for RootController. The FrontController has no delegate, but instead uses Interceptors to allow middleware to further process the request or to interrupt control flow. One integral change is that if no Action is found for the Request in the UrlMap, then no action will be taken by the FrontController. Instead, a NotFoundInterceptor should be used to send a HTTP 404 response in this event. --- data/controller.php | 4 +- http/action.php | 22 +-- http/action_controller.php | 3 +- ...ot_controller.php => front_controller.php} | 107 ++++-------- http/interceptor.php | 35 ++++ http/not_found_interceptor.php | 33 ++++ http/output_filter.php | 10 +- http/rest_adapter.php | 3 +- http/url_map.php | 12 +- testing/tests/http/action_controller_test.php | 6 +- ...ler_test.php => front_controller_test.php} | 157 +++++++++++------- testing/tests/http/output_filter_test.php | 4 +- testing/tests/http/rest_action_test.php | 10 +- testing/tests/http/rest_adapter_test.php | 28 ++-- testing/tests/http/url_map_test.php | 2 +- 15 files changed, 246 insertions(+), 190 deletions(-) rename http/{root_controller.php => front_controller.php} (69%) create mode 100644 http/interceptor.php create mode 100644 http/not_found_interceptor.php rename testing/tests/http/{root_controller_test.php => front_controller_test.php} (65%) diff --git a/data/controller.php b/data/controller.php index 79c338b..969c4cf 100644 --- a/data/controller.php +++ b/data/controller.php @@ -34,11 +34,13 @@ abstract class Controller extends http\RestAction protected $model = NULL; /*! Selects the Model object. */ - public function FilterRequest(http\Request $request, http\Response $response) + public function Invoke(http\Request $request, http\Response $response) { $this->model = $this->_SelectModel(); $this->model->SetFrom(array_merge( $request->data, $request->data['_POST'], $request->data['_GET'])); + + parent::Invoke($request, $response); } /*! Returns a new instance of the Model that this object will control. */ diff --git a/http/action.php b/http/action.php index 46f1859..0d8dd63 100644 --- a/http/action.php +++ b/http/action.php @@ -1,11 +1,11 @@ controller = $controller; } - /*! Accesses the RootController */ + /*! Accesses the FrontController */ public function controller() { return $this->controller; } - /*! - Called before the Action is Invoked(). - */ - public function FilterRequest(Request $request, Response $response) {} - /*! Performs the action and fills out the response's data model. */ public abstract function Invoke(Request $request, Response $response); - - /*! - Called after this has been Invoked(). - */ - public function FilterResponse(Request $request, Response $response) {} } diff --git a/http/action_controller.php b/http/action_controller.php index 3da7039..25a4b34 100644 --- a/http/action_controller.php +++ b/http/action_controller.php @@ -34,8 +34,7 @@ class ActionController extends Action { $method = $this->_GetActionMethod($request); if (!method_exists($this, $method)) { - $response->response_code = ResponseCode::NOT_FOUND; - $this->controller()->Stop(); + $this->controller()->SendResponseCode(ResponseCode::NOT_FOUND); return; } diff --git a/http/root_controller.php b/http/front_controller.php similarity index 69% rename from http/root_controller.php rename to http/front_controller.php index 75a25d7..b84f298 100644 --- a/http/root_controller.php +++ b/http/front_controller.php @@ -1,11 +1,11 @@ */ + private $interceptors = []; /*! Creates the controller with the request context information, typicallhy from the global scope ($GLOBALS), but can be injected for testing. - @param UrlMap The routing map - @param OutputFilter The object responsible for decorating output. - @param array& PHP globals array + @param array PHP globals array */ public function __construct(array $globals) { @@ -73,21 +72,18 @@ class RootController $this->output_filter = $output_filter; } - /*! Sets the delegate. */ - public function set_delegate($delegate) - { - $this->delegate = $delegate; - } - public function delegate() + /*! Registers an Interceptor that will be run before executing an Action. */ + public function AddInterceptor(Interceptor $interceptor) { - return $this->delegate; + $this->interceptors[] = $interceptor; } /*! - Createst the Request and Response that are used throughout the duration of - the execution. - */ - public function Run() + Called in index.php to process the current HTTP request. This initializes the + Request object from its data and then routes the request to generate the + response. + */ + public function ProcessRequest() { // The query rewriter module of the webserver rewrites a request from: // http://example.com/webapp/user/view/42 @@ -113,25 +109,20 @@ class RootController // Register self as the active instance. $GLOBALS[__CLASS__] = $this; - if ($this->delegate) - $this->delegate->OnInitialRequest($this->request, $this->response); - // Dispatch the request to an Action. $this->RouteRequest($this->request); // When control returns here, all actions have been invoked and it's time // to start the output filter and exit. - $this->Stop(); + $this->SendResponse(); } /*! Prevents any other Actions from executing. This starts the OutputFilter and then exits. */ - public function Stop() + public function SendResponse() { - if ($this->delegate) - $this->delegate->WillStop($this->request, $this->response); $this->output_filter->FilterOutput($this->request, $this->response); $this->_Exit(); } @@ -139,10 +130,10 @@ class RootController /*! Sets the response code and stops the controller. Returns void. */ - public function StopWithCode($code) + public function SendResponseCode($code) { $this->response->response_code = $code; - $this->Stop(); + $this->SendResponse(); } /*! @@ -150,13 +141,12 @@ class RootController location. @param string The destination location of the redirect. */ - public function StopWithRedirect($location) + public function SendResponseRedirect($location) { $this->response->headers['Location'] = $location; - $this->StopWithCode(ResponseCode::FOUND); + $this->SendResponseCode(ResponseCode::FOUND); } - /*! Wrapper around PHP exit(). */ @@ -166,45 +156,24 @@ class RootController } /*! - Invoked by Run() and can be invoked by others to evaluate and perform the - lookup in the UrlMap. This then calls InvokeAction(). + Given an Request object, this executes the action for the corresponding URL. + The action is located by performing a lookup in the UrlMap. Interceptors + are run before invoking the action. @param Request The Request whose URL will be routed */ public function RouteRequest(Request $request) { - if ($this->delegate) - $this->delegate->WillRouteRequest($request, $this->response); - $url_map_value = $this->url_map->Evaluate($request); $action = NULL; if ($url_map_value) $action = $this->url_map->LookupAction($url_map_value); - if (!$action) { - $this->response->response_code = ResponseCode::NOT_FOUND; - $this->Stop(); - return; - } + foreach ($this->interceptors as $interceptor) + $interceptor->DoIntercept($this, $action, $request, $this->response); - $this->InvokeAction($action); - } - - /*! - Used to run an Action and drive it through its states. - @param Action - */ - public function InvokeAction(Action $action) - { - if ($this->delegate) - $this->delegate->WillInvokeAction($action, $this->request, $this->response); - - $action->FilterRequest($this->request, $this->response); - $action->Invoke($this->request, $this->response); - $action->FilterResponse($this->request, $this->response); - - if ($this->delegate) - $this->delegate->DidInvokeAction($action, $this->request, $this->response); + if ($action) + $action->Invoke($request, $this->response); } /*! @@ -258,19 +227,3 @@ class RootController return $url . $new_path; } } - -/*! - Delegate for the root controller. All methods are optional. -*/ -interface RootControllerDelegate -{ - public function OnInitialRequest(Request $request, Response $response); - - public function WillRouteRequest(Request $request, Response $response); - - public function WillInvokeAction(Action $action, Request $request, Response $response); - - public function DidInvokeAction(Action $action, Request $request, Response $response); - - public function WillStop(Request $request, Response $response); -} diff --git a/http/interceptor.php b/http/interceptor.php new file mode 100644 index 0000000..15bf0ce --- /dev/null +++ b/http/interceptor.php @@ -0,0 +1,35 @@ +. + +namespace hoplite\http; + +/*! + An Interceptor runs as part of FrontController::RouteRequest() to provide + extra processing before the Action is Invoke()ed. The Action is provided to + allow the Interceptor to change the control flow based on characteristics + of the Action processor. An Interceptor may interrupt the control flow by + calling SendResponse() on the controller. +*/ +interface Interceptor +{ + /*! + Performs the action and fills out the response's data model. + */ + public function DoIntercept(FrontController $controller, + Action $action = NULL, + Request $request, + Response $response); +} diff --git a/http/not_found_interceptor.php b/http/not_found_interceptor.php new file mode 100644 index 0000000..a49fd41 --- /dev/null +++ b/http/not_found_interceptor.php @@ -0,0 +1,33 @@ +. + +namespace hoplite\http; + +require_once HOPLITE_ROOT . '/http/interceptor.php'; +require_once HOPLITE_ROOT . '/http/response_code.php'; + +class NotFoundInterceptor implements Interceptor +{ + public function DoIntercept(FrontController $controller, + Action $action, + Request $request, + Response $response) + { + if ($action === NULL) { + $controller->SendResponseCode(ResponseCode::NOT_FOUND); + } + } +} diff --git a/http/output_filter.php b/http/output_filter.php index 1e1925a..1ae998f 100644 --- a/http/output_filter.php +++ b/http/output_filter.php @@ -29,7 +29,7 @@ require_once HOPLITE_ROOT . '/views/template_loader.php'; */ class OutputFilter { - /*! @var RootController */ + /*! @var FrontController */ private $controller; /*! @var WeakInterface */ @@ -52,15 +52,15 @@ class OutputFilter const RENDER_TEMPLATE = 'template'; /*! - Constructor that takes a reference to the RootController. + Constructor that takes a reference to the FrontController. */ - public function __construct(RootController $controller) + public function __construct(FrontController $controller) { $this->controller = $controller; $this->delegate = new \hoplite\base\WeakInterface('hoplite\http\OutputFilterDelegate'); } - /*! Accessor for the RootController. */ + /*! Accessor for the FrontController. */ public function controller() { return $this->controller; } /*! Accessors for the delegate. */ @@ -71,7 +71,7 @@ class OutputFilter public function delegate() { return $this->delegate->Get(); } /*! @brief Main entry point for output filtering - This is called from the RootController to begin processing the output and + This is called from the FrontController to begin processing the output and generating the response. */ public function FilterOutput(Request $request, Response $response) diff --git a/http/rest_adapter.php b/http/rest_adapter.php index 0329177..aeec994 100644 --- a/http/rest_adapter.php +++ b/http/rest_adapter.php @@ -29,9 +29,10 @@ abstract class RestAdapter extends ActionController /*! @var RestAction The RESTful interface which will be adapted. */ protected $action = NULL; - public function FilterRequest(Request $request, Response $response) + public function Invoke(Request $request, Response $response) { $this->action = $this->_GetRestAction(); + parent::Invoke($request, $response); } /*! Gets the RestAction that will be adapted. */ diff --git a/http/url_map.php b/http/url_map.php index bc40a67..8bf450a 100644 --- a/http/url_map.php +++ b/http/url_map.php @@ -25,7 +25,7 @@ require_once HOPLITE_ROOT . '/base/functions.php'; */ class UrlMap { - /*! @var RootController */ + /*! @var FrontController */ private $controller; /*! @var array The map of URLs to actions. */ @@ -35,15 +35,15 @@ class UrlMap private $file_loader = NULL; /*! - Constructs the object with a reference to the RootController. - @param RootController + Constructs the object with a reference to the FrontController. + @param FrontController */ - public function __construct(RootController $controller) + public function __construct(FrontController $controller) { $this->controller = $controller; } - /*! Accessor for the RootController */ + /*! Accessor for the FrontController */ public function controller() { return $this->controller; } /*! Gets the URL map */ @@ -55,7 +55,7 @@ class UrlMap The keys can be either a URL prefix or a regular expression. For URL prefixes, the pattern is matched relative to the root of the entry- - point as specified by the RootController. Patterns should not begin with a + point as specified by the FrontController. Patterns should not begin with a slash. Path fragment parameter extraction can be performed as well. For example, the pattern 'user/view/{id}' will match a URL like http://example.com/webapp/user/view/42 diff --git a/testing/tests/http/action_controller_test.php b/testing/tests/http/action_controller_test.php index 5781b97..6e74c12 100644 --- a/testing/tests/http/action_controller_test.php +++ b/testing/tests/http/action_controller_test.php @@ -34,7 +34,7 @@ class ActionControllerTest extends \PHPUnit_Framework_TestCase public function setUp() { $globals = array(); - $this->fixture = new TestActionController(new http\RootController($globals)); + $this->fixture = new TestActionController(new http\FrontController($globals)); $this->request = new http\Request(); $this->response = new http\Response(); } @@ -49,11 +49,11 @@ class ActionControllerTest extends \PHPUnit_Framework_TestCase public function testFailedDispatch() { $globals = array(); - $mock = $this->getMock('hoplite\http\RootController', array(), array($globals)); + $mock = $this->getMock('hoplite\http\FrontController', array('SendResponse'), array($globals)); $this->fixture = new TestActionController($mock); $mock->expects($this->once()) - ->method('Stop'); + ->method('SendResponse'); $this->request->data['action'] = 'nothing'; $this->fixture->Invoke($this->request, $this->response); diff --git a/testing/tests/http/root_controller_test.php b/testing/tests/http/front_controller_test.php similarity index 65% rename from testing/tests/http/root_controller_test.php rename to testing/tests/http/front_controller_test.php index bd10a93..e3a86bd 100644 --- a/testing/tests/http/root_controller_test.php +++ b/testing/tests/http/front_controller_test.php @@ -1,11 +1,11 @@ did_filter_request = TRUE; + $this->did_invoke = TRUE; } +} - public function Invoke(http\Request $q, http\Response $s) +class ClosureInterceptor implements http\Interceptor +{ + private $interceptor; + public $did_intercept = FALSE; + + public function __construct($interceptor) { - $this->did_invoke = TRUE; + $this->interceptor = $interceptor; } - public function FilterResponse(http\Request $q, http\Response $s) + public function DoIntercept(http\FrontController $controller, + http\Action $action = NULL, + http\Request $request, + http\Response $response) { - $this->did_filter_response = TRUE; + $this->did_intercept = TRUE; + if ($this->interceptor) { + $interceptor = $this->interceptor; + $interceptor($controller, $action, $request, $response); + } } } -class RootControllerTest extends \PHPUnit_Framework_TestCase +class FrontControllerTest extends \PHPUnit_Framework_TestCase { /*! - Configures a mock RootControler. + Configures a mock FrontControler. @param array|NULL Array of methods to mock @param varargs Constructor parameters. - @return Mock RootControler + @return Mock FrontControler */ public function ConfigureMock() { $args = func_get_args(); - return $this->getMock('hoplite\http\RootController', $args[0], array_slice($args, 1)); + return $this->getMock('hoplite\http\FrontController', $args[0], array_slice($args, 1)); } - public function testRun() + public function testProcessRequest() { $globals = array('_SERVER' => array( 'REQUEST_METHOD' => 'GET', 'PATH_INFO' => '/some/action/42' )); - $mock = $this->ConfigureMock(array('RouteRequest', 'Stop'), $globals); + $mock = $this->ConfigureMock(array('RouteRequest', 'SendResponse'), $globals); $mock->request()->url = 'some/action/42'; @@ -73,42 +85,20 @@ class RootControllerTest extends \PHPUnit_Framework_TestCase ->with($this->equalTo($mock->request())); $mock->expects($this->once()) - ->method('Stop'); - - $mock->Run(); - } - - public function testInvokeAction() - { - $globals = array(); - $fixture = new http\RootController($globals); - - $action = new ActionReporter($fixture); + ->method('SendResponse'); - $this->assertFalse($action->did_filter_request); - $this->assertFalse($action->did_invoke); - $this->assertFalse($action->did_filter_response); - - $fixture->InvokeAction($action); - - $this->assertTrue($action->did_filter_request); - $this->assertTrue($action->did_invoke); - $this->assertTrue($action->did_filter_response); + $mock->ProcessRequest(); } public function testRouteRequest() { $globals = array(); - $mock = $this->ConfigureMock(array('Stop', 'InvokeAction'), $globals); + $mock = $this->ConfigureMock(array('SendResponse', 'InvokeAction'), $globals); $mock->request()->url = 'some/action/42'; $map_value = 'ActionReporter'; $action = new ActionReporter($mock); - $mock->expects($this->once()) - ->method('InvokeAction') - ->with($this->isInstanceOf('hoplite\test\ActionReporter')); - $url_map = $this->getMock('hoplite\http\UrlMap', array(), array($mock)); $url_map->expects($this->once()) ->method('Evaluate') @@ -121,17 +111,19 @@ class RootControllerTest extends \PHPUnit_Framework_TestCase $mock->set_url_map($url_map); $mock->RouteRequest($mock->request()); + + $this->assertTrue($action->did_invoke); } public function testRouteRequestInvalid() { $globals = array(); - $mock = $this->ConfigureMock(array('Stop'), $globals); + $mock = $this->ConfigureMock(array('SendResponse'), $globals); $mock->request()->url = 'another/action'; - $mock->expects($this->once()) - ->method('Stop'); + $mock->expects($this->never()) + ->method('SendResponse'); $url_map = $this->getMock('hoplite\http\UrlMap', array(), array($mock)); $url_map->expects($this->once()) @@ -140,10 +132,10 @@ class RootControllerTest extends \PHPUnit_Framework_TestCase $mock->set_url_map($url_map); $mock->RouteRequest($mock->request()); - $this->assertEquals(http\ResponseCode::NOT_FOUND, $mock->response()->response_code); + // Nothing should happen for a non-routed request. } - public function testStop() + public function testSendResponse() { $globals = array(); $mock = $this->ConfigureMock(array('_Exit'), $globals); @@ -158,7 +150,7 @@ class RootControllerTest extends \PHPUnit_Framework_TestCase $this->isInstanceOf('hoplite\http\Response')); $mock->set_output_filter($output_filter); - $mock->Stop(); + $mock->SendResponse(); } public function testStopWithRedirect() @@ -176,7 +168,7 @@ class RootControllerTest extends \PHPUnit_Framework_TestCase $mock->set_output_filter($output_filter); - $mock->StopWithRedirect('/foo/bar'); + $mock->SendResponseRedirect('/foo/bar'); $this->assertEquals('/foo/bar', $mock->response()->headers['Location']); $this->assertEquals(http\ResponseCode::FOUND, $mock->response()->response_code); @@ -192,7 +184,7 @@ class RootControllerTest extends \PHPUnit_Framework_TestCase 'SERVER_PORT' => 80, ), ); - $mock = new \hoplite\http\RootController($globals); + $mock = new \hoplite\http\FrontController($globals); $this->assertEquals($mock->MakeURL('/'), '/hoplite/webapp/'); $this->assertEquals($mock->MakeURL('/', TRUE), 'http://www.bluestatic.org/hoplite/webapp/'); @@ -202,7 +194,7 @@ class RootControllerTest extends \PHPUnit_Framework_TestCase $globals['_SERVER']['HTTPS'] = 'on'; $globals['_SERVER']['SERVER_PORT'] = 443; - $mock = new \hoplite\http\RootController($globals); + $mock = new \hoplite\http\FrontController($globals); $this->assertEquals($mock->MakeURL('/'), '/hoplite/webapp/'); $this->assertEquals($mock->MakeURL('/', TRUE), 'https://www.bluestatic.org/hoplite/webapp/'); @@ -210,13 +202,13 @@ class RootControllerTest extends \PHPUnit_Framework_TestCase $this->assertEquals($mock->MakeURL('/path/3', TRUE), 'https://www.bluestatic.org/hoplite/webapp/path/3'); $globals['_SERVER']['SERVER_PORT'] = 8080; - $mock = new \hoplite\http\RootController($globals); + $mock = new \hoplite\http\FrontController($globals); $this->assertEquals($mock->MakeURL('/path/2'), '/hoplite/webapp/path/2'); $this->assertEquals($mock->MakeURL('/', TRUE), 'https://www.bluestatic.org:8080/hoplite/webapp/'); $this->assertEquals($mock->MakeURL('/path/3', TRUE), 'https://www.bluestatic.org:8080/hoplite/webapp/path/3'); } - public function testAbsolutifyRoot() + public function testAbsolutifyFront() { $globals = array( '_SERVER' => array( @@ -226,14 +218,14 @@ class RootControllerTest extends \PHPUnit_Framework_TestCase 'SERVER_PORT' => 80, ), ); - $mock = new \hoplite\http\RootController($globals); + $mock = new \hoplite\http\FrontController($globals); $this->assertEquals($mock->MakeURL('/'), '/hoplite/webapp/'); $this->assertEquals($mock->MakeURL('/', TRUE), 'http://www.bluestatic.org/hoplite/webapp/'); $globals['_SERVER']['HTTPS'] = 'on'; $globals['_SERVER']['SERVER_PORT'] = 443; - $mock = new \hoplite\http\RootController($globals); + $mock = new \hoplite\http\FrontController($globals); $this->assertEquals($mock->MakeURL('/'), '/hoplite/webapp/'); $this->assertEquals($mock->MakeURL('/', TRUE), 'https://www.bluestatic.org/hoplite/webapp/'); @@ -241,9 +233,60 @@ class RootControllerTest extends \PHPUnit_Framework_TestCase $this->assertEquals($mock->MakeURL('/path/3', TRUE), 'https://www.bluestatic.org/hoplite/webapp/path/3'); $globals['_SERVER']['SERVER_PORT'] = 8080; - $mock = new \hoplite\http\RootController($globals); + $mock = new \hoplite\http\FrontController($globals); $this->assertEquals($mock->MakeURL('/path/2'), '/hoplite/webapp/path/2'); $this->assertEquals($mock->MakeURL('/', TRUE), 'https://www.bluestatic.org:8080/hoplite/webapp/'); $this->assertEquals($mock->MakeURL('/path/3', TRUE), 'https://www.bluestatic.org:8080/hoplite/webapp/path/3'); } + + public function testThreeInterceptors() + { + $interceptors = [ + new ClosureInterceptor(NULL), + new ClosureInterceptor(NULL), + new ClosureInterceptor(NULL), + ]; + + $mock = new \hoplite\http\FrontController([]); + $mock->set_url_map(new http\UrlMap($mock)); + + foreach ($interceptors as $interceptor) { + $mock->AddInterceptor($interceptor); + } + + $mock->RouteRequest($mock->request()); + + foreach ($interceptors as $interceptor) { + $this->assertTrue($interceptor->did_intercept); + } + } + + public function testInterruptInterceptor() + { + $i1 = new ClosureInterceptor(NULL); + $i2 = new ClosureInterceptor(function($controller, $action, $request, $response) { + $controller->SendResponseCode(400); + }); + $test = $this; + $i3 = new ClosureInterceptor(function($controller, $action, $request, $response) use ($test) { + $test->assertEquals(400, $response->response_code); + }); + + $mock = $this->ConfigureMock(['SendResponse'], []); + $mock->set_url_map(new http\UrlMap($mock)); + $mock->AddInterceptor($i1); + $mock->AddInterceptor($i2); + $mock->AddInterceptor($i3); + + $mock->expects($this->once()) + ->method('SendResponse'); + + $mock->RouteRequest($mock->request()); + + $this->assertEquals(400, $mock->response()->response_code); + $this->assertTrue($i1->did_intercept); + $this->assertTrue($i2->did_intercept); + // i3 would not normally run but because _Exit is mocked, the script does + // not finish. + } } diff --git a/testing/tests/http/output_filter_test.php b/testing/tests/http/output_filter_test.php index b101e24..dba9e74 100644 --- a/testing/tests/http/output_filter_test.php +++ b/testing/tests/http/output_filter_test.php @@ -31,7 +31,7 @@ class OutputFilterTest extends \PHPUnit_Framework_TestCase { public function setUp() { - $this->fixture = new TestOutputFilter(new http\RootController(array())); + $this->fixture = new TestOutputFilter(new http\FrontController(array())); } public function testEncodeXML() @@ -50,7 +50,7 @@ class OutputFilterTest extends \PHPUnit_Framework_TestCase 1bar<strong>baz</strong>moobaa XML; - + $this->assertEquals($expected, $this->fixture->T_EncodeXML($array)); $obj = new \stdClass(); diff --git a/testing/tests/http/rest_action_test.php b/testing/tests/http/rest_action_test.php index fb6c36b..afae0db 100644 --- a/testing/tests/http/rest_action_test.php +++ b/testing/tests/http/rest_action_test.php @@ -1,11 +1,11 @@ fixture = new TestRestAction(new http\RootController($globals)); + $this->fixture = new TestRestAction(new http\FrontController($globals)); $this->request = new http\Request(); $this->response = new http\Response(); } @@ -72,7 +72,7 @@ class RestActionTest extends \PHPUnit_Framework_TestCase public function testInvalid() { $globals = array(); - $mock = $this->getMock('hoplite\http\RootController', array('Stop'), array($globals)); + $mock = $this->getMock('hoplite\http\FrontController', array('Stop'), array($globals)); $this->fixture = new TestRestAction($mock); diff --git a/testing/tests/http/rest_adapter_test.php b/testing/tests/http/rest_adapter_test.php index 629d52a..7a4d01b 100644 --- a/testing/tests/http/rest_adapter_test.php +++ b/testing/tests/http/rest_adapter_test.php @@ -39,7 +39,7 @@ class RestAdapterTest extends \PHPUnit_Framework_TestCase public function setUp() { $globals = array(); - $this->controller = new http\RootController($globals); + $this->controller = new http\FrontController($globals); $this->fixture = new TestRestAdapter($this->controller); $this->request = $this->controller->request(); $this->response = $this->controller->response(); @@ -59,7 +59,7 @@ class RestAdapterTest extends \PHPUnit_Framework_TestCase { $this->request->http_method = 'GET'; $this->request->data['action'] = 'fetch'; - $this->controller->InvokeAction($this->fixture); + $this->fixture->Invoke($this->request, $this->response); $this->RestExpectSingleTrue('did_get'); } @@ -67,7 +67,7 @@ class RestAdapterTest extends \PHPUnit_Framework_TestCase { $this->request->http_method = 'POST'; $this->request->data['action'] = 'fetch'; - $this->controller->InvokeAction($this->fixture); + $this->fixture->Invoke($this->request, $this->response); $this->RestExpectSingleTrue('did_get'); } @@ -75,7 +75,7 @@ class RestAdapterTest extends \PHPUnit_Framework_TestCase { $this->request->http_method = 'PUT'; $this->request->data['action'] = 'fetch'; - $this->controller->InvokeAction($this->fixture); + $this->fixture->Invoke($this->request, $this->response); $this->RestExpectSingleTrue(NULL); $this->assertEquals(http\ResponseCode::METHOD_NOT_ALLOWED, $this->response->response_code); } @@ -84,7 +84,7 @@ class RestAdapterTest extends \PHPUnit_Framework_TestCase { $this->request->http_method = 'POST'; $this->request->data['action'] = 'update'; - $this->controller->InvokeAction($this->fixture); + $this->fixture->Invoke($this->request, $this->response); $this->RestExpectSingleTrue('did_post'); } @@ -92,7 +92,7 @@ class RestAdapterTest extends \PHPUnit_Framework_TestCase { $this->request->http_method = 'GET'; $this->request->data['action'] = 'update'; - $this->controller->InvokeAction($this->fixture); + $this->fixture->Invoke($this->request, $this->response); $this->RestExpectSingleTrue(NULL); $this->assertEquals(http\ResponseCode::METHOD_NOT_ALLOWED, $this->response->response_code); } @@ -101,7 +101,7 @@ class RestAdapterTest extends \PHPUnit_Framework_TestCase { $this->request->http_method = 'POST'; $this->request->data['action'] = 'delete'; - $this->controller->InvokeAction($this->fixture); + $this->fixture->Invoke($this->request, $this->response); $this->RestExpectSingleTrue('did_delete'); } @@ -109,7 +109,7 @@ class RestAdapterTest extends \PHPUnit_Framework_TestCase { $this->request->http_method = 'GET'; $this->request->data['action'] = 'delete'; - $this->controller->InvokeAction($this->fixture); + $this->fixture->Invoke($this->request, $this->response); $this->RestExpectSingleTrue(NULL); $this->assertEquals(http\ResponseCode::METHOD_NOT_ALLOWED, $this->response->response_code); } @@ -118,7 +118,7 @@ class RestAdapterTest extends \PHPUnit_Framework_TestCase { $this->request->http_method = 'POST'; $this->request->data['action'] = 'insert'; - $this->controller->InvokeAction($this->fixture); + $this->fixture->Invoke($this->request, $this->response); $this->RestExpectSingleTrue('did_put'); } @@ -126,7 +126,7 @@ class RestAdapterTest extends \PHPUnit_Framework_TestCase { $this->request->http_method = 'GET'; $this->request->data['action'] = 'insert'; - $this->controller->InvokeAction($this->fixture); + $this->fixture->Invoke($this->request, $this->response); $this->RestExpectSingleTrue(NULL); $this->assertEquals(http\ResponseCode::METHOD_NOT_ALLOWED, $this->response->response_code); } @@ -134,17 +134,17 @@ class RestAdapterTest extends \PHPUnit_Framework_TestCase public function testInvalid() { $globals = array(); - $mock = $this->getMock('hoplite\http\RootController', array('Stop'), array($globals)); + $mock = $this->getMock('hoplite\http\FrontController', array('SendResponse'), array($globals)); $this->fixture = new TestRestAdapter($mock); $mock->expects($this->once()) - ->method('Stop'); + ->method('SendResponse'); $this->request->http_method = 'HEAD'; - $this->controller->InvokeAction($this->fixture); + $this->fixture->Invoke($mock->request(), $mock->response()); $this->RestExpectSingleTrue('___none___'); - $this->assertEquals(http\ResponseCode::NOT_FOUND, $this->response->response_code); + $this->assertEquals(http\ResponseCode::NOT_FOUND, $mock->response()->response_code); } } diff --git a/testing/tests/http/url_map_test.php b/testing/tests/http/url_map_test.php index 72fbaf2..01fd813 100644 --- a/testing/tests/http/url_map_test.php +++ b/testing/tests/http/url_map_test.php @@ -29,7 +29,7 @@ class UrlMapTest extends \PHPUnit_Framework_TestCase public function setUp() { $globals = array(); - $this->fixture = new http\UrlMap(new http\RootController($globals)); + $this->fixture = new http\UrlMap(new http\FrontController($globals)); } public function testSimpleEvaluate() -- 2.43.5