如何在Laravel5上检查带有单元测试的路由

时间:2016-02-03 08:36:55

标签: php unit-testing laravel laravel-5

我尝试过使用单元测试,但它没有用。不知何故,收到的状态代码是404.然后,终端声明原因是异常' Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException'。

routes.php文件

Route::get('/', function() {
    return view('toppage')->with('contents', "");
});

ExampleTest.php     

use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;

class ExampleTest extends TestCase
{
    /**
     * A basic test example.
     *
     * @return void
     */
    public function testExample()
    {
        $this->visit('/')
             ->see('Where lane');
    }
}

nignx.conf(摘录文件的一部分)

location / {
        index            index.html index.php;
    }

    location ~* /MAMP(.*)$ {
        root             /Applications/MAMP/bin;
        index            index.php;

        location ~ \.php$ {
            try_files        $uri =404;
            fastcgi_pass     unix:/Applications/MAMP/Library/logs/fastcgi/nginxFastCGI.sock;
            fastcgi_param    SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include          fastcgi_params;
        }
    }

1 个答案:

答案 0 :(得分:1)

如果您想查看是否可以访问该路线。最好验证该链接上的文本。

试试这个:

with open('u_ele_stu.txt', 'wb') as f:
    pickle.dump(u_ele_stu, f)

with open('ele_pl_stu.txt', 'wb') as f:
    pickle.dump(ele_pl_stu, f)

如果此操作失败,请先尝试在浏览器中获取该网站。清除路线,缓存并仔细检查页面上是否存在“Where lane”文本。