PHPUnit和Laravel';s中间件
目前,我使用以下中间件为用户登录的视图提供常量:PHPUnit和Laravel';s中间件,php,phpunit,laravel-5.1,middleware,service-provider,Php,Phpunit,Laravel 5.1,Middleware,Service Provider,目前,我使用以下中间件为用户登录的视图提供常量: <?php namespace App\Http\Middleware; use Closure; /* * Middleware has replaced what used to be "filters" */ class AddConstantsFilesToAllRoutes { /** * Handle an incoming request. * * @param \Illumi
<?php
namespace App\Http\Middleware;
use Closure;
/*
* Middleware has replaced what used to be "filters"
*/
class AddConstantsFilesToAllRoutes
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
require_once app_path('constants') . '/constants2013andearlier.php';
require_once app_path('constants') . '/constants20142015.php';
require_once app_path('constants') . '/constants20152016.php';
return $next($request);
}
}
如果有人能帮我找出如何让PHPUnit识别我的常数,我将不胜感激。这是我的PHPUnit测试:
/**
* Tests to see if the login page loads
*/
public function testToSeeIfLoginLoads()
{
$this->visit('/login')
->see('Login')->see('Email Address')->see('Password')
->type('email@email.com', 'email')->type('mypassword', 'password')
->press('Log In')->see('Complete Course Summary');
}
问题不在于我使用withoutMiddleware()方法或类在PHPUnit测试中禁用了中间件。然而,我上面描述的问题的行为就像我禁用了中间件一样,至少是禁用了提供常量的中间件
提前感谢。只是为了确保,在测试类的顶端,您仍然具有在没有中间件的情况下禁用中间件的特性?是的,我有:使用Illumb\Foundation\Testing\而不使用中间件;使用Illumb\Foundation\Testing\DatabaseMigrations;使用Illumb\Foundation\Testing\DatabaseTransactions;只是为了确保,在测试类的顶部,您仍然具有禁用中间件而不使用中间件的特性?是的,我有:使用Illumb\Foundation\Testing\而不使用中间件;使用Illumb\Foundation\Testing\DatabaseMigrations;使用Illumb\Foundation\Testing\DatabaseTransactions;
/**
* Tests to see if the login page loads
*/
public function testToSeeIfLoginLoads()
{
$this->visit('/login')
->see('Login')->see('Email Address')->see('Password')
->type('email@email.com', 'email')->type('mypassword', 'password')
->press('Log In')->see('Complete Course Summary');
}