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. */
<?php
// Hoplite
// Copyright (c) 2011 Blue Static
-//
+//
// This program is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation, either version 3 of the License, or any later version.
-//
+//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
*/
abstract class Action
{
- /*! \var RootController */
+ /*! \var FrontController */
private $controller;
/*!
- Creates a new action with a reference to the RootController.
- @param RootController
+ Creates a new action with a reference to the FrontController.
+ @param FrontController
*/
public function __construct($controller)
{
$this->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) {}
}
{
$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;
}
<?php
// Hoplite
-// Copyright (c) 2011 Blue Static
-//
+// Copyright (c) 2015 Blue Static
+//
// This program is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation, either version 3 of the License, or any later version.
-//
+//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
namespace hoplite\http;
+require_once HOPLITE_ROOT . '/http/interceptor.php';
require_once HOPLITE_ROOT . '/http/request.php';
require_once HOPLITE_ROOT . '/http/response.php';
require_once HOPLITE_ROOT . '/http/response_code.php';
/*!
- The RootController is meant to be invoked from the index.php of the
+ The FrontController is meant to be invoked from the index.php of the
application.
*/
-class RootController
+class FrontController
{
/*! @var Request */
private $request = NULL;
/*! @var OutputFilter */
private $output_filter = NULL;
- /*! @var RootControllerDelegate */
- private $delegate = NULL;
+ /*! @var Array<Interceptor> */
+ 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)
{
$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
// 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();
}
/*!
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();
}
/*!
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().
*/
}
/*!
- 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);
}
/*!
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);
-}
--- /dev/null
+<?php
+// Hoplite
+// Copyright (c) 2015 Blue Static
+//
+// This program is free software: you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by the Free
+// Software Foundation, either version 3 of the License, or any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program. If not, see <http://www.gnu.org/licenses/>.
+
+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);
+}
--- /dev/null
+<?php
+// Hoplite
+// Copyright (c) 2015 Blue Static
+//
+// This program is free software: you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by the Free
+// Software Foundation, either version 3 of the License, or any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program. If not, see <http://www.gnu.org/licenses/>.
+
+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);
+ }
+ }
+}
*/
class OutputFilter
{
- /*! @var RootController */
+ /*! @var FrontController */
private $controller;
/*! @var WeakInterface<OutputFilterDelegate> */
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. */
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)
/*! @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. */
*/
class UrlMap
{
- /*! @var RootController */
+ /*! @var FrontController */
private $controller;
/*! @var array The map of URLs to actions. */
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 */
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
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();
}
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);
<?php
// Hoplite
-// Copyright (c) 2011 Blue Static
-//
+// Copyright (c) 2015 Blue Static
+//
// This program is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation, either version 3 of the License, or any later version.
-//
+//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
use hoplite\http as http;
require_once HOPLITE_ROOT . '/http/action.php';
+require_once HOPLITE_ROOT . '/http/front_controller.php';
+require_once HOPLITE_ROOT . '/http/interceptor.php';
require_once HOPLITE_ROOT . '/http/output_filter.php';
-require_once HOPLITE_ROOT . '/http/root_controller.php';
require_once HOPLITE_ROOT . '/http/url_map.php';
class ActionReporter extends http\Action
{
- public $did_filter_request = FALSE;
public $did_invoke = FALSE;
- public $did_filter_response = FALSE;
- public function FilterRequest(http\Request $q, http\Response $s)
+ public function Invoke(http\Request $q, http\Response $s)
{
- $this->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';
->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')
$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())
$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);
$this->isInstanceOf('hoplite\http\Response'));
$mock->set_output_filter($output_filter);
- $mock->Stop();
+ $mock->SendResponse();
}
public function testStopWithRedirect()
$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);
'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/');
$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(
'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/');
$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.
+ }
}
{
public function setUp()
{
- $this->fixture = new TestOutputFilter(new http\RootController(array()));
+ $this->fixture = new TestOutputFilter(new http\FrontController(array()));
}
public function testEncodeXML()
<response><test>1</test><foo>bar</foo><bar><strong>baz</strong></bar><baz><poo>moo</poo><moo>baa</moo></baz></response>
XML;
-
+
$this->assertEquals($expected, $this->fixture->T_EncodeXML($array));
$obj = new \stdClass();
<?php
// Hoplite
// Copyright (c) 2011 Blue Static
-//
+//
// This program is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation, either version 3 of the License, or any later version.
-//
+//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
namespace hoplite\test;
use hoplite\http as http;
+require_once HOPLITE_ROOT . '/http/front_controller.php';
require_once HOPLITE_ROOT . '/http/rest_action.php';
-require_once HOPLITE_ROOT . '/http/root_controller.php';
require_once TEST_ROOT . '/tests/http/fixtures.php';
class RestActionTest extends \PHPUnit_Framework_TestCase
public function setUp()
{
$globals = array();
- $this->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();
}
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);
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();
{
$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');
}
{
$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');
}
{
$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);
}
{
$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');
}
{
$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);
}
{
$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');
}
{
$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);
}
{
$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');
}
{
$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);
}
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);
}
}
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()