public function testConsoles()
{
$this->specify("CLI Console doesn't work with typical parameters", function () {
$di = new CliFactoryDefault();
$di->set('data', function () {
return "data";
});
$console = new Console();
$console->setDI($di);
$dispatcher = $console->getDI()->getShared('dispatcher');
$console->handle([]);
expect($dispatcher->getTaskName())->equals('main');
expect($dispatcher->getActionName())->equals('main');
expect($dispatcher->getParams())->equals([]);
expect($dispatcher->getReturnedValue())->equals('mainAction');
$console->handle(['task' => 'echo']);
expect($dispatcher->getTaskName())->equals('echo');
expect($dispatcher->getActionName())->equals('main');
expect($dispatcher->getParams())->equals([]);
expect($dispatcher->getReturnedValue())->equals('echoMainAction');
$console->handle(['task' => 'main', 'action' => 'hello']);
expect($dispatcher->getTaskName())->equals('main');
expect($dispatcher->getActionName())->equals('hello');
expect($dispatcher->getParams())->equals([]);
expect($dispatcher->getReturnedValue())->equals('Hello !');
$console->handle(['task' => 'main', 'action' => 'hello', 'World', '######']);
expect($dispatcher->getTaskName())->equals('main');
expect($dispatcher->getActionName())->equals('hello');
expect($dispatcher->getParams())->equals(array('World', '######'));
expect($dispatcher->getReturnedValue())->equals('Hello World######');
});
$this->specify("CLI Console doesn't throw exception when module isn't found", function () {
$di = new CliFactoryDefault();
$di->set('data', function () {
return "data";
});
$console = new Console();
$console->setDI($di);
$dispatcher = $console->getDI()->getShared('dispatcher');
// testing module
$console->handle(['module' => 'devtools', 'task' => 'main', 'action' => 'hello', 'World', '######']);
}, ['throws' => [\Phalcon\Cli\Console\Exception::class, "Module 'devtools' isn't registered in the console container"]]);
$this->specify("CLI Console doesn't throw exception when task isn't found", function () {
$di = new CliFactoryDefault();
$console = new Console();
$console->setDI($di);
$dispatcher = $console->getDI()->getShared('dispatcher');
$dispatcher->setDefaultNamespace('Dummy\\');
// testing namespace
$console->handle(['task' => 'main', 'action' => 'hello', 'World', '!']);
}, ['throws' => [\Phalcon\Cli\Dispatcher\Exception::class, 'Dummy\\MainTask handler class cannot be loaded']]);
}