测试laravel路线识别方法类型

时间:2018-05-13 10:35:23

标签: laravel routes phpunit

如果请求是获取或发布,我怎样才能获得Laravel路线?

我尝试使用以下

测试我的laravel路线
public function testRoutes()
    {
        $app = app();
        $routes = $app->routes->getRoutes();


        /**
         * Test if mynamespace routes are redirected to login page if is not the login page
         */
        echo  PHP_EOL;

        foreach ($routes as $route) {

            if(strpos($route->getName(),'mynamespace::' ) !== false ) {

                $url = $route->uri;

                //$appURL = env('APP_URL') .'/';

                $response = $this->get($url);

                if((int)$response->status() !== 200 ){
                    echo   $url . ' (FAILED) did not return 200. The response is ' . $response->status();
                    $this->assertTrue(false);
                } else {
                    echo  $url . ' (success ?)';
                    $this->assertTrue(true);
                }
                echo  PHP_EOL;

            }
        }
    }

但我想暂时排除帖子请求

0 个答案:

没有答案