/** * This method is called before a test is executed. */ protected function setUp() { parent::setUp(); $module = new ModuleStub(TEMP_DIR); $module->setController('test-controller', 'Titon\\Test\\Stub\\ControllerStub'); $app = new Application(new Request(), new Response()); $app->addModule('test-module', $module); $this->object = new FrontDispatcher(); $this->object->setApplication($app); $this->object->setRequest($app->getRequest()); $this->object->setResponse($app->getResponse()); $this->object->setParams(['module' => 'test-module', 'controller' => 'test-controller', 'action' => 'actionNoArgs', 'args' => []]); }
* @license http://opensource.org/licenses/bsd-license.php * @link http://titon.io */ use Titon\Cache\Cache; use Titon\Common\Registry; use Titon\Controller\Controller\ErrorController; use Titon\Db\Database; use Titon\Environment\Environment; use Titon\G11n\G11n; use Titon\Mvc\Application; use Titon\Mvc\View; use Titon\View\Helper\BlockHelper; use Titon\View\Helper\Html\AssetHelper; use Titon\View\Helper\Html\HtmlHelper; use Titon\View\View\Engine\TemplateEngine; $app = Application::getInstance(); /** * -------------------------------------------------------------- * Component Mapping * -------------------------------------------------------------- * * Components are objects that should be accessed globally * through the application layer. These components are the * gears that drive the application. * * All components can be accessed through their key by * calling get() on the application object. */ $app->set('env', new Environment(['bootstrapPath' => RESOURCES_DIR . 'environments/']))->set('cache', new Cache())->set('g11n', new G11n())->set('db', new Database()); /** * --------------------------------------------------------------
* to composer in case we need to modify the loader. */ $composer = (require_once VENDOR_DIR . 'autoload.php'); Registry::set($composer, 'titon.composer'); /** * -------------------------------------------------------------- * Application Bootstrap * -------------------------------------------------------------- * * Now it's time to start the application. We can do this by * instantiating a new Application object. We'll use a multiton * so that we can access the Application object statically. * Lastly, pass in a Request and Response object as constructor * parameters, which will be passed down to child classes. */ $app = Application::getInstance('default', [new Request(), new Response()]); /** * Bootstrap the application with configuration. * Order here is extremely critical, do not change! */ foreach (['setup', 'registry', 'environments', 'cache', 'locales', 'database', 'modules', 'routes'] as $config) { $path = sprintf(RESOURCES_DIR . 'bootstrap/%s.php', $config); if (file_exists($path)) { require_once $path; } } /** * Now we can run the application. We want to pass the webroot * so that symlinking of assets work properly. */ $app->run(WEB_DIR);
/** * {@inheritdoc} */ public function bootstrap(Application $app) { $app->emit('mvc.module.bootstrap', [$this]); }
/** * Test that getController() returns a controller instance. */ public function testGetController() { $module = new ModuleStub(TEMP_DIR); $module->setController('test-controller', 'Titon\\Test\\Stub\\ControllerStub'); $app = new Application(new Request(), new Response()); $app->addModule('test-module', $module); $this->object->setApplication($app); $this->object->setRequest(new Request()); $this->object->setResponse(new Response()); $this->object->setParams(['module' => 'test-module', 'controller' => 'test-controller']); $this->assertInstanceOf('Titon\\Test\\Stub\\ControllerStub', $this->object->getController()); }