/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp() { $service = new UrlRewriterService(); $service->addRoutes(array(new Route('TestAction', '/test/:result', array(new RouteParameter('result'))), new Route('Unknown', '/bad/action'))); $app = \Fwk\Core\Application::factory('testApp')->addListener(new \Fwk\Core\Components\RequestMatcher\RequestMatcherListener('requestMatcher'))->addListener(new UrlRewriterListener('urlRewriter')); $app['TestAction'] = function ($result) { return $result; }; $app->getServices()->set('requestMatcher', new ClassDefinition('Fwk\\Core\\Components\\RequestMatcher\\RequestMatcher'), true); $app->getServices()->set('urlRewriter', $service, true); $this->object = $app; }
public function testWrongService() { $service = new ViewHelperService(); $service->add('test', new TestHelper2()); $app = \Fwk\Core\Application::factory('testApp')->addListener(new \Fwk\Core\Components\RequestMatcher\RequestMatcherListener('requestMatcher'))->addListener(new ViewHelperListener('requestMatcher')); $app['TestAction'] = '+' . TEST_RESOURCES_DIR . DIRECTORY_SEPARATOR . 'viewhelper_template.php'; $app->getServices()->set('requestMatcher', new \Fwk\Core\Components\RequestMatcher\RequestMatcher(), true); $app->getServices()->set('viewHelperService', $service, true); $this->object = $app; $req = Request::create('/TestAction.action'); $this->setExpectedException('Fwk\\Core\\Components\\ViewHelper\\Exception'); $this->object->run($req); }
/** */ protected function setUp() { $this->object = Application::factory('testApp')->addListener(new Components\RequestMatcher\RequestMatcherListener('requestMatcher'))->register('TestSimpleClosureAction', ProxyFactory::factory(function () { return "test"; }))->register('TestClosureWithParams', ProxyFactory::factory(function ($name) { return "hello " . $name; }))->register('TestClosureResponse', ProxyFactory::factory(function () { return new RedirectResponse('http://www.example.org'); }))->register('TestSimpleController', ProxyFactory::factory('Fwk\\Core\\TestController:show'))->register('TestHelloController', ProxyFactory::factory('Fwk\\Core\\HelloController:show'))->register('TestServiceClosure', ProxyFactory::factory('@actionService'))->register('TestServiceController', ProxyFactory::factory('@helloController:show'))->register('TestContextAwareClosure', ProxyFactory::factory(function ($context) { return $context; }))->register('TestServicesAwareClosure', ProxyFactory::factory(function ($services) { return $services; })); $this->object->getServices()->set('requestMatcher', new ClassDefinition('Fwk\\Core\\Components\\RequestMatcher\\RequestMatcher'), true); $this->object->getServices()->set('actionService', function () { return "testService"; }, true); $this->object->getServices()->set('helloController', new ClassDefinition('Fwk\\Core\\HelloController'), true); }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp() { $service = new ResultTypeService(); $service->addType('json', new JsonResultType()); $service->addType('php', new PhpTemplateResultType(array('templatesDir' => TEST_RESOURCES_DIR))); $service->addType('redirect', new RedirectResultType()); $service->register('TestAction', \Fwk\Core\Action\Result::SUCCESS, 'json'); $service->register('TestAction', \Fwk\Core\Action\Result::REDIRECT, 'redirect', array('uri' => '/')); $service->register('TestAction', 'template', 'php', array('file' => 'phptemplate_resulttype.php')); $app = \Fwk\Core\Application::factory('testApp')->addListener(new \Fwk\Core\Components\RequestMatcher\RequestMatcherListener('requestMatcher'))->addListener(new ResultTypeListener('resultTypeService')); $app['TestAction'] = function ($result) { return $result; }; $app['TestActionObj'] = function () { return new \stdClass(); }; $app->getServices()->set('requestMatcher', new ClassDefinition('Fwk\\Core\\Components\\RequestMatcher\\RequestMatcher'), true); $app->getServices()->set('resultTypeService', $service, true); $this->object = $app; }
/** * @return Application */ public function execute($appName, Container $services = null) { $this->sources = array_reverse($this->sources); $app = Application::factory($appName, $services); if (null === $services) { $services = $app->getServices(); } $app->addListener(new DescriptorListener($this)); $this->loadIniFiles(); $this->loadServices($services); foreach ($this->loadListeners($services) as $listener) { $app->addListener($listener); } foreach ($this->loadPlugins($services) as $plugin) { $app->plugin($plugin); } foreach ($this->loadActions() as $actionName => $str) { $app->register($actionName, ProxyFactory::factory($str)); } return $app; }
protected function getApp() { return \Fwk\Core\Application::factory('testApp'); }