Phalcon\Test\Unit\Cli\DispatcherTest::testDispatcher PHP Method

testDispatcher() public method

public testDispatcher ( )
    public function testDispatcher()
    {
        $this->specify("CLI Dispatcher doesn't work with typical parameters", function () {
            $di = new CliFactoryDefault();
            $di->set('data', function () {
                return "data";
            });
            $dispatcher = new Dispatcher();
            $dispatcher->setDI($di);
            $dispatcher->dispatch();
            expect($dispatcher->getTaskName())->equals('main');
            expect($dispatcher->getActionName())->equals('main');
            expect($dispatcher->getParams())->equals([]);
            expect($dispatcher->getReturnedValue())->equals('mainAction');
            $dispatcher->setTaskName('echo');
            $dispatcher->dispatch();
            expect($dispatcher->getTaskName())->equals('echo');
            expect($dispatcher->getActionName())->equals('main');
            expect($dispatcher->getParams())->equals([]);
            expect($dispatcher->getReturnedValue())->equals('echoMainAction');
            $dispatcher->setTaskName('main');
            $dispatcher->setActionName('hello');
            $dispatcher->dispatch();
            expect($dispatcher->getTaskName())->equals('main');
            expect($dispatcher->getActionName())->equals('hello');
            expect($dispatcher->getParams())->equals([]);
            expect($dispatcher->getReturnedValue())->equals('Hello !');
            $dispatcher->setActionName('hello');
            $dispatcher->setParams(array('World', '######'));
            $dispatcher->dispatch();
            expect($dispatcher->getTaskName())->equals('main');
            expect($dispatcher->getActionName())->equals('hello');
            expect($dispatcher->getParams())->equals(array('World', '######'));
            expect($dispatcher->getReturnedValue())->equals('Hello World######');
            $dispatcher->setActionName('hello');
            $dispatcher->setParams(array('hello' => 'World', 'goodbye' => 'Everybody'));
            $dispatcher->dispatch();
            expect($dispatcher->hasParam('hello'))->true();
            expect($dispatcher->hasParam('goodbye'))->true();
            expect($dispatcher->hasParam('salutations'))->false();
            // testing namespace
            try {
                $dispatcher->setDefaultNamespace('Dummy\\');
                $dispatcher->setTaskName('main');
                $dispatcher->setActionName('hello');
                $dispatcher->setParams(array('World'));
                $dispatcher->dispatch();
                expect($dispatcher->getTaskName())->equals('main');
                expect($dispatcher->getActionName())->equals('hello');
                expect($dispatcher->getParams())->equals(array('World'));
                expect($dispatcher->getReturnedValue())->equals('Hello World!');
            } catch (\Exception $e) {
                expect($e->getMessage())->equals('Dummy\\MainTask handler class cannot be loaded');
            }
        });
    }