我有一个工作测试套件,但是我的本地环境有两件事发生了变化。1)我已将 Homestead 升级到版本 7 和 2)我已将我的应用程序升级到 Laravel 5.6。
现在我遇到了 PHPUnit 耗尽内存分配的问题,除非我添加ini_set('memory_limit', '1024M');
到我的createApplication
方法的开头。然后我的测试套件进一步发展,但最终完全停止。
奇怪的是,如果我运行该套件孤立地停止的测试,它就会通过。事实上,如果我只测试可能包含 10 个测试的整个文件,测试都通过了。仅在尝试一次性测试整个套件时才会停止...
就好像事情没有在测试之间得到清理,它只是填满了内存并冻结了。
但我使用的是默认的 TestCasetearDown
方法:
/**
* Clean up the testing environment before the next test.
*
* @return void
*/
protected function tearDown()
{
if ($this->app) {
foreach ($this->beforeApplicationDestroyedCallbacks as $callback) {
call_user_func($callback);
}
$this->app->flush();
$this->app = null;
}
$this->setUpHasRun = false;
if (property_exists($this, 'serverVariables')) {
$this->serverVariables = [];
}
if (property_exists($this, 'defaultHeaders')) {
$this->defaultHeaders = [];
}
if (class_exists('Mockery')) {
if ($container = Mockery::getContainer()) {
$this->addToAssertionCount($container->mockery_getExpectationCount());
}
Mockery::close();
}
if (class_exists(Carbon::class)) {
Carbon::setTestNow();
}
$this->afterApplicationCreatedCallbacks = [];
$this->beforeApplicationDestroyedCallbacks = [];
Artisan::forgetBootstrappers();
}
据我了解,因此重置了测试之间的所有内容。
我在内存中使用 sqlite 作为我的测试数据库。
升级后还有其他人遇到问题吗?
更新
我最终明白了这一点。这是 PHP 7.2 的一个问题。降级到 7.1 并且所有测试都通过了默认内存限制没有问题。