我在L5.1中使用了新的集成测试.我在运行测试类时遇到了一些奇怪的错误 - 在我正在测试的页面上大多是404.奇怪的是,当我过滤到单独的测试时,测试通过很好.当我运行它所属的整个测试类或测试套件时,它失败了404.该路由在浏览器中工作,并且当我自己运行时测试通过,所以它显然不是有效的错误.
代码看起来像这样:
class MyTest extends \TestCase
{
use WithoutMiddleware;
public function __construct() {
parent::__construct();
$this->mock = m::mock('MyApp\Stuff\Repository');
$this->validator = m::mock('Illuminate\Validation\Factory');
$this->mockedClass = m::mock('MyApp\Stuff\Service');
}
/**
* @test
*/
public function it_should_get_all_thingies() {
$this->mockedClass->shouldReceive('someMethod')
->once()
->andReturn('yay');
$this->app->instance('MyApp\Stuff\Service', $this->mockedClass);
$this->visit('/api/v1/thingies');
}
}
Run Code Online (Sandbox Code Playgroud)
当我跑
phpunit --filter=it_should_get_all_thingies,它工作正常.当我运行时
phpunit --filter=MyTest,它会死于404.我可以将相关的URL从错误消息复制到浏览器中,它可以正常工作.
我能想到的唯一其他相关事实是,这是从L4.2到5.0到5.1的更新.
任何帮助是极大的赞赏.