Php 使用Laravel 5.4进行示例测试时出现错误404
使用Laravel 5.4,我无法运行为phpunit提供的示例测试:Php 使用Laravel 5.4进行示例测试时出现错误404,php,laravel,phpunit,laravel-5.4,Php,Laravel,Phpunit,Laravel 5.4,使用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\DatabaseTransacti
<?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);
}
}
根目录下的my.env
包含:
APP_URL=http://localhost/~username/myproject/public
我看到了,但答案是无用的
有什么想法吗
编辑:
请注意,url
http://localhost/~username/myproject/public/
完全可以通过浏览器工作。添加虚拟主机,并将该域用于应用程序URL
在Ubuntu 17.04中,您可以通过在/etc/apache2/sites available
中创建一个.conf
文件来实现此目的,该文件包含以下内容:
<VirtualHost *:80>
DocumentRoot "/path/to/your/laravel/project/public"
ServerName name.of.your.virtual.host
<Directory "/path/to/your/laravel/project/public">
AllowOverride All
</Directory>
</VirtualHost>
最后重新启动apache:
systemctl reload apache2
您的网站通过浏览器正常工作吗?@NigelRen是的,网站的稳定版本正在工作。当前的开发版本会为每个页面返回错误500,但通过浏览器工作的根url除外。这就是我想运行测试的原因,但这个示例是对根url的请求,它首先不起作用。您可以添加
echo-env('APP_-url','?')代码>到您的测试,以验证它是否具有正确的配置。@NigelRenecho env('APP_URL','?')代码>返回<代码>http://localhost/~username/myproject/public
,所以它是正确的配置,不是吗?添加虚拟主机,并将该域用作应用程序URL
sudo a2ensite name.of.your.file.conf
systemctl reload apache2