Phalcon\Test\Unit\Mvc\RouterTest::testUsingCallbacksBeforeMatchRoute PHP Method

testUsingCallbacksBeforeMatchRoute() public method

Tests using callbacks before match route
Since: 2013-01-08
Author: Andy Gutierrez ([email protected])
    public function testUsingCallbacksBeforeMatchRoute()
    {
        $this->specify('The Route::beforeMatch does not use callback as expected', function () {
            $router = $this->getRouter(false);
            $trace = 0;
            $router->add('/static/route')->beforeMatch(function () use(&$trace) {
                $trace++;
                return false;
            });
            $router->add('/static/route2')->beforeMatch(function () use(&$trace) {
                $trace++;
                return true;
            });
            $router->handle();
            expect($router->wasMatched())->false();
            $router->handle('/static/route');
            expect($router->wasMatched())->false();
            $router->handle('/static/route2');
            expect($router->wasMatched())->true();
            expect($trace)->equals(2);
        });
    }