Phalcon\Test\Unit\Cli\ConsoleTest::testArgumentRouter PHP Method

testArgumentRouter() public method

public testArgumentRouter ( )
    public function testArgumentRouter()
    {
        $this->specify("CLI Console doesn't work with arguments", function () {
            $di = new CliFactoryDefault();
            $di->setShared('router', function () {
                $router = new Router(true);
                return $router;
            });
            $console = new Console();
            $console->setDI($di);
            $dispatcher = $console->getDI()->getShared('dispatcher');
            $console->setArgument(array('php'))->handle();
            expect($dispatcher->getTaskName())->equals('main');
            expect($dispatcher->getActionName())->equals('main');
            expect($dispatcher->getParams())->equals([]);
            expect($dispatcher->getReturnedValue())->equals('mainAction');
            $console->setArgument(array('php', 'echo'))->handle();
            expect($dispatcher->getTaskName())->equals('echo');
            expect($dispatcher->getActionName())->equals('main');
            expect($dispatcher->getParams())->equals([]);
            expect($dispatcher->getReturnedValue())->equals('echoMainAction');
            $console->setArgument(array('php', 'main', 'hello'))->handle();
            expect($dispatcher->getTaskName())->equals('main');
            expect($dispatcher->getActionName())->equals('hello');
            expect($dispatcher->getParams())->equals([]);
            expect($dispatcher->getReturnedValue())->equals('Hello !');
            $console->setArgument(array('php', 'main', 'hello', 'World', '######'))->handle();
            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 work with arguments (2)", function () {
            $di = new CliFactoryDefault();
            $di->setShared('router', function () {
                $router = new Router(true);
                return $router;
            });
            $console = new Console();
            $console->setDI($di);
            $dispatcher = $console->getDI()->getShared('dispatcher');
            // testing namespace
            $dispatcher->setDefaultNamespace('Dummy\\');
            $console->setArgument(array('php', 'main', 'hello', 'World', '!'));
            $console->handle();
        }, ['throws' => [\Phalcon\Cli\Dispatcher\Exception::class, 'Dummy\\MainTask handler class cannot be loaded']]);
    }