【发布时间】:2017-10-28 21:41:11
【问题描述】:
使用 Laravel 5.4,我无法运行为 phpunit 提供的示例测试:
<?php
namespace Tests\Feature;
use Tests\TestCase;
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 testBasicTest()
{
$response = $this->get('/');
$response->assertStatus(200);
}
}
从我的项目输出的根目录运行命令phpunit:
PHPUnit 6.0.10 by Sebastian Bergmann and contributors.
F. 2 / 2 (100%)
Time: 147 ms, Memory: 12.00MB
There was 1 failure:
1) Tests\Feature\ExampleTest::testBasicTest
Expected status code 200 but received 404.
Failed asserting that false is true.
/home/username/public_html/myproject/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestResponse.php:76
/home/username/public_html/myproject/tests/Feature/ExampleTest.php:21
我的.env 在根目录下包含:
APP_URL=http://localhost/~username/myproject/public
我看到了this similar question,但是回答没用。
有什么想法吗?
编辑:
请注意,网址 http://localhost/~username/myproject/public/ 可以通过浏览器完美运行。
【问题讨论】:
-
您的网站可以通过浏览器正常运行吗?
-
@NigelRen 是的,该站点的稳定版本正在运行。当前的开发版本为每个页面返回错误 500,但通过浏览器工作的根 url 除外。这就是我想运行测试的原因,但是这个对根 url 的请求的示例首先不起作用
-
您能否将
echo env('APP_URL', '?');添加到您的测试中以验证它具有正确的配置。 -
@NigelRen
echo env('APP_URL', '?');返回了http://localhost/~username/myproject/public,所以这是正确的配置,不是吗? -
添加虚拟主机,并将该域用于 APP_URL
标签: php laravel phpunit laravel-5.4