public function testConsoles() { $di = new Phalcon\DI\FactoryDefault\CLI(); $di->set('data', function () { return "data"; }); $console = new \Phalcon\CLI\Console(); $console->setDI($di); $dispatcher = $console->getDI()->getShared('dispatcher'); $console->handle(array()); $this->assertEquals($dispatcher->getTaskName(), 'main'); $this->assertEquals($dispatcher->getActionName(), 'main'); $this->assertEquals($dispatcher->getParams(), array()); $this->assertEquals($dispatcher->getReturnedValue(), 'mainAction'); $console->handle(array('task' => 'echo')); $this->assertEquals($dispatcher->getTaskName(), 'echo'); $this->assertEquals($dispatcher->getActionName(), 'main'); $this->assertEquals($dispatcher->getParams(), array()); $this->assertEquals($dispatcher->getReturnedValue(), 'echoMainAction'); $console->handle(array('task' => 'main', 'action' => 'hello')); $this->assertEquals($dispatcher->getTaskName(), 'main'); $this->assertEquals($dispatcher->getActionName(), 'hello'); $this->assertEquals($dispatcher->getParams(), array()); $this->assertEquals($dispatcher->getReturnedValue(), 'Hello !'); $console->handle(array('task' => 'main', 'action' => 'hello', 'World', '######')); $this->assertEquals($dispatcher->getTaskName(), 'main'); $this->assertEquals($dispatcher->getActionName(), 'hello'); $this->assertEquals($dispatcher->getParams(), array('World', '######')); $this->assertEquals($dispatcher->getReturnedValue(), 'Hello World######'); // testing module try { $console->handle(array('module' => 'devtools', 'task' => 'main', 'action' => 'hello', 'World', '######')); $this->assertEquals($dispatcher->getTaskName(), 'main'); $this->assertEquals($dispatcher->getActionName(), 'hello'); $this->assertEquals($dispatcher->getParams(), array('World', '######')); $this->assertEquals($dispatcher->getReturnedValue(), 'Hello World######'); } catch (Exception $e) { $this->assertEquals($e->getMessage(), "Module 'devtools' isn't registered in the console container"); } // testing namespace try { $dispatcher->setDefaultNamespace('Dummy\\'); $console->handle(array('task' => 'main', 'action' => 'hello', 'World', '!')); $this->assertEquals($dispatcher->getTaskName(), 'main'); $this->assertEquals($dispatcher->getActionName(), 'hello'); $this->assertEquals($dispatcher->getParams(), array('World')); $this->assertEquals($dispatcher->getReturnedValue(), 'Hello World!'); } catch (Exception $e) { $this->assertEquals($e->getMessage(), 'Dummy\\MainTask handler class cannot be loaded'); } }
public function testArgumentOptions() { $di = new Phalcon\DI\FactoryDefault\CLI(); $di->setShared('router', function () { $router = new \Phalcon\Cli\Router(true); return $router; }); $console = new \Phalcon\CLI\Console(); $console->setDI($di); $dispatcher = $console->getDI()->getShared('dispatcher'); $console->setArgument(array('php', '-opt1', '--option2', '--option3=hoge', 'main', 'hello', 'World', '######'))->handle(); $this->assertEquals($dispatcher->getTaskName(), 'main'); $this->assertEquals($dispatcher->getActionName(), 'hello'); $this->assertEquals($dispatcher->getParams(), array('World', '######')); $this->assertEquals($dispatcher->getReturnedValue(), 'Hello World######'); $this->assertEquals($dispatcher->getOptions(), array('opt1' => true, 'option2' => true, 'option3' => 'hoge')); $console->setArgument(array('php', 'main', '-opt1', 'hello', '--option2', 'World', '--option3=hoge', '######'))->handle(); $this->assertEquals($dispatcher->getTaskName(), 'main'); $this->assertEquals($dispatcher->getActionName(), 'hello'); $this->assertEquals($dispatcher->getParams(), array('World', '######')); $this->assertEquals($dispatcher->getReturnedValue(), 'Hello World######'); $this->assertEquals($dispatcher->getOptions(), array('opt1' => true, 'option2' => true, 'option3' => 'hoge')); }