【发布时间】:2016-05-02 08:45:08
【问题描述】:
我正在尝试在开发环境中运行 phpunit。但是,每当我有一个使用 press() 函数的函数时,我都会收到 404 错误。
1) LoginTest::testLoginWithInvalidCredentials
A request to [http://localhost/set/public/auth/login] failed. Received status code [404].
C:\inetpub\wwwroot\set\vendor\laravel\framework\src\Illuminate\Foundation\Testing\InteractsWithPages.php:165
C:\inetpub\wwwroot\set\vendor\laravel\framework\src\Illuminate\Foundation\Testing\InteractsWithPages.php:63
C:\inetpub\wwwroot\set\vendor\laravel\framework\src\Illuminate\Foundation\Testing\InteractsWithPages.php:85
C:\inetpub\wwwroot\set\vendor\laravel\framework\src\Illuminate\Foundation\Testing\InteractsWithPages.php:658
C:\inetpub\wwwroot\set\vendor\laravel\framework\src\Illuminate\Foundation\Testing\InteractsWithPages.php:645
C:\inetpub\wwwroot\set\tests\LoginTest.php:49
Caused by exception 'Symfony\Component\HttpKernel\Exception\NotFoundHttpException' in C:\inetpub\wwwroot\set\vendor\laravel\framework\src\Illuminate\Routing\RouteCollection.php:161
当我访问http://localhost/set/public/auth/login 时,URL 工作正常。事实上,当我使用该网站时,一切正常。另外,如果我在本地机器上运行 phpunit,我根本不会收到错误消息。
我已经检查了我的 .env 文件,并且一切都检查了系统是否可以正常工作。而且我的路线似乎也正确。如果我手动运行测试,一切都会正确执行。它只是运行这个失败的 phpunit 测试。
任何关于在哪里看的方向都将不胜感激。
<?php
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class LoginTest extends TestCase
{
use DatabaseTransactions;
public function testLoginPageOk()
{
$this->visit('/')
->see('You are accessing');
}
public function testRedirectToLoginPage()
{
$this->call('GET','/');
$this->assertRedirectedTo('auth/login');
}
public function testAuthLoginRoutes()
{
$this->call('GET', '/auth/login');
$this->see('You are accessing');
}
public function testLoginWithInvalidCredentials()
{
$this->visit('/auth/login')
->type('asdf', 'username')
->type('gibberish', 'password')
->press('Sign in')
->see('These credentials do not match our records.');
}
}
这是我的路线文件:
<?php
// This group requires a user to be logged in.
Route::group(['middleware' => 'auth'], function() {
// when you login, if you were not going to a page, you get directed
// to /home. Let's push that to the actual home page.
Route::get('home', function(){ return redirect('/');});
Route::get('/', 'HomeController@index');
});
// Authentication routes. Doesn't need to be logged in.
Route::get('auth/login', 'Auth\AuthController@getLogin');
Route::post('auth/login', 'Auth\AuthController@postLogin');
Route::get('auth/logout', 'Auth\AuthController@getLogout');
最后我的 .env 文件如下:
APP_ENV=local
APP_DEBUG=true
APP_KEY=ycDUbCfgo81OJfc1TjNBjggAtXqwES5I
APP_URL=http://localhost/set/public/
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
MAIL_DRIVER=smtp
MAIL_HOST=ilsausmail
MAIL_PORT=25
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
【问题讨论】: