public function testApplicationModulesDefinitionClosure() { // Creates the autoloader $loader = new \Phalcon\Loader(); $loader->registerNamespaces(array('Frontend\\Controllers' => __DIR__ . '/modules/frontend/controllers/', 'Backend\\Controllers' => __DIR__ . '/modules/backend/controllers/')); $loader->register(); $_GET['_url'] = '/login'; Phalcon\DI::reset(); $di = new Phalcon\DI\FactoryDefault(); $di->set('router', function () { $router = new Phalcon\Mvc\Router(false); $router->add('/index', array('controller' => 'index', 'module' => 'frontend', 'namespace' => 'Frontend\\Controllers\\')); $router->add('/login', array('controller' => 'login', 'module' => 'backend', 'namespace' => 'Backend\\Controllers\\')); return $router; }); $application = new Phalcon\Mvc\Application(); $view = new \Phalcon\Mvc\View(); $application->registerModules(array('frontend' => function ($di) use($view) { $di->set('view', function () use($view) { $view = new \Phalcon\Mvc\View(); $view->setViewsDir(__DIR__ . '/modules/frontend/views/'); return $view; }); }, 'backend' => function ($di) use($view) { $di->set('view', function () use($view) { $view->setViewsDir(__DIR__ . '/modules/backend/views/'); return $view; }); })); $application->setDi($di); $this->assertEquals($application->handle()->getContent(), '<html>here</html>' . PHP_EOL); $loader->unregister(); }
public function testEvents() { $loader = new Phalcon\Loader(); $loader->registerDirs(array("unit-tests/vendor/example/other/")); $loader->registerClasses(array("AvecTest" => "unit-tests/vendor/example/other/Avec/")); $loader->registerNamespaces(array("Avec\\Test" => "unit-tests/vendor/example/other/Avec/")); $loader->registerPrefixes(array("Avec_" => "unit-tests/vendor/example/other/Avec/")); $eventsManager = new Phalcon\Events\Manager(); $trace = array(); $eventsManager->attach('loader', function ($event, $loader) use(&$trace) { $trace[$event->getType()] = $loader->getCheckedPath(); }); $loader->setEventsManager($eventsManager); $loader->register(); $test = new VousTest3(); $this->assertEquals(get_class($test), 'VousTest3'); $this->assertEquals($trace, array('beforeCheckClass' => NULL, 'beforeCheckPath' => 'unit-tests/vendor/example/other/VousTest3.php', 'pathFound' => 'unit-tests/vendor/example/other/VousTest3.php', 'afterCheckClass' => 'unit-tests/vendor/example/other/VousTest3.php')); $loader->unregister(); }