public function _initialize() { require Configuration::projectDir() . 'init_autoloader.php'; $this->applicationConfig = (require Configuration::projectDir() . $this->config['config']); if (isset($applicationConfig['module_listener_options']['config_cache_enabled'])) { $applicationConfig['module_listener_options']['config_cache_enabled'] = false; } Console::overrideIsConsole(false); }
public function it_aborts_bootstrap_on_console(MvcEvent $event, Application $application, ServiceLocatorInterface $serviceLocator, AccessListener $listener, EventManager $eventManager) { Console::overrideIsConsole(true); $application->getEventManager()->willReturn($eventManager); $serviceLocator->get(AccessListener::class)->willReturn($listener); $application->getServiceManager()->willReturn($serviceLocator); $event->getApplication()->willReturn($application); $listener->attach($eventManager)->shouldNotBeCalled(); $this->onBootstrap($event); }
public function testCanForceInstance() { $console = Console::getInstance('Posix'); $this->assertTrue($console instanceof Adapter\AdapterInterface); $this->assertTrue($console instanceof Adapter\Posix); Console::overrideIsConsole(null); Console::resetInstance(); $console = Console::getInstance('Windows'); $this->assertTrue($console instanceof Adapter\AdapterInterface); $this->assertTrue($console instanceof Adapter\Windows); }
public function testUrlHelperUnderConsoleParadigmShouldReturnHttpRoutes() { Console::overrideIsConsole(true); $this->serviceManager->get('Application')->bootstrap(); $request = $this->serviceManager->get('Request'); $this->assertInstanceOf('Zend\\Console\\Request', $request); $viewHelpers = $this->serviceManager->get('ViewHelperManager'); $urlHelper = $viewHelpers->get('url'); $test = $urlHelper('test'); $this->assertEquals('/test', $test); }
/** * @return \Zend\Mvc\Application */ public function getApplication() { if ($this->spiffyApplication) { return $this->spiffyApplication; } Console::overrideIsConsole($this->getUseConsoleRequest()); $this->spiffyApplication = SpiffyTest::getInstance()->getApplication(); $events = $this->spiffyApplication->getEventManager(); $events->detach($this->spiffyApplication->getServiceManager()->get('SendResponseListener')); return $this->spiffyApplication; }
public function bootstrap() { // mark the MVC doesn't use console Console::overrideIsConsole(false); // bootstrap application $application = $this->getServiceManager()->get('Application')->bootstrap(); // set service manager self::$serviceManager = $application->getServiceManager(); self::$documentManager = $this->getServiceManager()->get('doctrine.odm.documentmanager.default'); self::$dbName = $this->getServiceManager()->get('config')['doctrine']['odm']['connection']['default']['dbname']; }
public function _initialize() { require Configuration::projectDir() . 'init_autoloader.php'; $this->applicationConfig = (require Configuration::projectDir() . $this->config['config']); if (isset($this->applicationConfig['module_listener_options']['config_cache_enabled'])) { $this->applicationConfig['module_listener_options']['config_cache_enabled'] = false; } Console::overrideIsConsole(false); //grabServiceFromContainer may need client in beforeClass hooks of modules or helpers $this->client = new ZF2Connector(); $this->client->setApplicationConfig($this->applicationConfig); }
public function _before(\Codeception\TestCase $test) { $applicationConfig = (require \Codeception\Configuration::projectDir() . $this->config['config']); if (isset($applicationConfig['module_listener_options']['config_cache_enabled'])) { $applicationConfig['module_listener_options']['config_cache_enabled'] = false; } Console::overrideIsConsole(false); $this->application = Application::init($applicationConfig); $events = $this->application->getEventManager(); $events->detach($this->application->getServiceManager()->get('SendResponseListener')); $this->client->setApplication($this->application); }
public function testOnBootstrap() { $event = new MvcEvent(); $application = new Application([], Bootstrap::getServiceManager()); $em = new EventManager(); $application->setEventManager($em); $event->setApplication($application); $isConsole = Console::isConsole(); Console::overrideIsConsole(false); $this->module->onBootstrap($event); Console::overrideIsConsole($isConsole); $this->assertCount(1, $em->getListeners(MvcEvent::EVENT_DISPATCH)); $this->assertCount(1, $em->getListeners(MvcEvent::EVENT_RENDER)); }
public function testApplicationClassAndTestRestoredConsoleFlag() { $this->assertTrue(Console::isConsole(), '1. Console::isConsole returned false in initial test'); $this->getApplication(); $this->assertFalse(Console::isConsole(), '2. Console::isConsole returned true after retrieving application'); $this->tearDown(); $this->assertTrue(Console::isConsole(), '3. Console::isConsole returned false after tearDown'); Console::overrideIsConsole(false); parent::setUp(); $this->assertFalse(Console::isConsole(), '4. Console::isConsole returned true after parent::setUp'); $this->getApplication(); $this->assertFalse(Console::isConsole(), '5. Console::isConsole returned true after retrieving application'); parent::tearDown(); $this->assertFalse(Console::isConsole(), '6. Console.isConsole returned true after parent::tearDown'); }
public function createServer($name = 'default') { Console::overrideIsConsole(false); $configuration = $this->configuration; $smConfig = isset($configuration['service_manager']) ? $configuration['service_manager'] : array(); $serviceManager = new ServiceManager(new ServiceManagerConfig($smConfig)); $serviceManager->setService('ApplicationConfig', $configuration); $serviceManager->get('ModuleManager')->loadModules(); $application = new Application($configuration, $serviceManager); $application->setServerOptions($this->options->getServer($name)); $allow = $serviceManager->getAllowOverride(); $serviceManager->setAllowOverride(true); $serviceManager->setService('application', $application); $serviceManager->setAllowOverride($allow); return $application->bootstrap(); }
public function setUp() { // Used by \KJSencha\Service\ApiFactory::createService \Zend\Console\Console::overrideIsConsole(false); $sl = ServiceManagerFactory::getServiceManager(); /* @var $manager DirectManager */ $manager = $sl->get('kjsencha.direct.manager'); /* @var $apiFactory \KJSencha\Direct\Remoting\Api\Api */ $api = $sl->get('kjsencha.api'); $this->controller = new DirectController($manager, $api); $this->request = new Request(); $this->routeMatch = new RouteMatch(array('controller' => 'kjsencha_direct')); $this->event = new MvcEvent(); $this->event->setRouteMatch($this->routeMatch); $this->controller->setEvent($this->event); }
/** * @requires PHP 5.4 */ public function testClosureThisIsControllerInstance() { Console::overrideIsConsole(false); $app = App::init(); $test = $this; $appRequest = new Request(); $appRequest->setUri('http://localhost/test/blah'); $app->getMvcEvent()->setRequest($appRequest); $app->route('/test/:param1', function () use($test) { $test->assertInstanceOf('ZeffMu\\ClosureController', $this); return 'test'; }); // overriding send response listener $app->getEventManager()->attach(MvcEvent::EVENT_FINISH, function (EventInterface $e) { $e->stopPropagation(); }, 1000); $app->run(); }
public function testApplicationClassAndTestRestoredConsoleFlag() { $this->assertTrue(Console::isConsole()); $this->getApplication(); $this->assertFalse(Console::isConsole()); $this->tearDown(); $this->assertTrue(Console::isConsole()); Console::overrideIsConsole(false); parent::setUp(); $this->assertFalse(Console::isConsole()); $this->getApplication(); $this->assertFalse(Console::isConsole()); parent::tearDown(); $this->assertFalse(Console::isConsole()); }
public function setUp() { Console::overrideIsConsole(false); parent::setUp(); $this->request = new Request(); $this->request->setHeaders(new Headers()); $this->routeMatch = new RouteMatch(array('controller' => $this->controllerName)); $this->event = $this->getApplication()->getMvcEvent(); $this->event->setRequest($this->request); $this->event->setRouteMatch($this->routeMatch); $this->event->getRouter()->setRequestUri(new HttpUri('http://localhost')); if (null === $this->controller) { if (null === $this->controllerName) { throw new PHPUnit_Framework_Exception('No controller name was specified in the test'); } $this->controller = $this->getServiceManager()->get('ControllerLoader')->get($this->controllerName); } $this->controller->setEvent($this->event); }
/** * Get the application object * @return \Zend\Mvc\ApplicationInterface */ public function getApplication() { if ($this->application) { return $this->application; } $appConfig = $this->applicationConfig; Console::overrideIsConsole($this->getUseConsoleRequest()); $this->application = Application::init($appConfig); $events = $this->application->getEventManager(); $events->detach($this->application->getServiceManager()->get('SendResponseListener')); return $this->application; }
/** * Reset is console flag * * @see \Spork\Test\TestCase\TestCaseService::tearDown() */ protected function tearDown() { Console::overrideIsConsole($this->isConsole); }
/** * Bootstrap for unit tests * * Copyright (C) 2011-2015 Holger Schletz <*****@*****.**> * * 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 2 of the License, or (at your option) * 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ error_reporting(-1); ini_set('memory_limit', '300M'); date_default_timezone_set('Europe/Berlin'); require_once __DIR__ . '/../../../Library/Application.php'; require_once 'Zend/Console/Console.php'; // Pretend to be not on a console to force choice of HTTP route over console route. \Zend\Console\Console::overrideIsConsole(false); \Library\Application::init('Console', false); \Locale::setDefault('de_DE'); // Force environment-independent locale // Get absolute path to vfsStream library \Zend\Loader\AutoloaderFactory::factory(array('\\Zend\\Loader\\StandardAutoloader' => array('namespaces' => array('org\\bovigo\\vfs' => stream_resolve_include_path('org/bovigo/vfs')))));