【发布时间】:2017-11-23 19:08:03
【问题描述】:
我在运行 Laravel 附带的基本测试时遇到问题:
app/tests/Feature/ExampleTest.php
class ExampleTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function testBasicTest()
{
$response = $this->get('/');
$response->assertStatus(200);
$this->assertTrue(true);
}
}
当我运行它时,我得到了异常NotFoundHttpException。我可以毫无问题地在浏览器中访问我的网站。这个问题似乎适用于我的所有路线。
使用 Laravel 5.4
路由/在app/routes/web.php中定义。
【问题讨论】:
-
你能把routes.php的代码贴出来吗?
-
app/routes/web.php:
<?php Route::get('/', function () { return view('welcome'); }); -
所以你想访问 testBasicTest() 函数但不返回视图,对吧?
-
我刚刚发现了一些非常有趣的东西。我的机器托管多个网页。在我的 Laravel .env 文件中,我有:
APP_URL=https://myserver/product-service,将其更改为APP_URL=https://myserver可以防止 NotFoundHttpException。然而,这不是解决方案 -
似乎与这个问题有关:stackoverflow.com/questions/22967227/…
标签: php laravel unit-testing routes phpunit