Fatal error: Call to a member function run() on null in {path to the test file}
Fatal error: Call to a member function run() on null in {path to the test file}
我正在使用 PHPUnit 5.7.23 和 phinx 0.9.1,
public function setUp(){
$this->phinx = new PhinxApplication;
$this->phinx->setAutoExit(false);
$this->phinx->run(new StringInput('migrate'), new NullOutput);
$this->phinx->run(new StringInput('seed:run'), new NullOutput);
}
public function tearDown(){
$this->phinx->run(new StringInput('rollback -t 0'), new NullOutput);
}
这是我测试文件的代码,每次我添加
public function testExampleFunction(){
$this->assertTrue(true);
}
在线失败:
$this->phinx->run(new StringInput('rollback -t 0'), new NullOutput);
错误:
Fatal error: Call to a member function run() on null in {path to the
test file}
当我改变这个时:
public function tearDown()
{
if (!empty($this->phinx)) {
$this->phinx->run(new StringInput('rollback -t 0'), new NullOutput);
}
}
它通过了,但是由于没有回滚,我的下一个测试崩溃了
您使用的是命名空间 (PSR-4) 吗?
如果是这样,你应该有这行代码:
use Phinx\Console\PhinxApplication;
我正在使用 PHPUnit 5.7.23 和 phinx 0.9.1,
public function setUp(){
$this->phinx = new PhinxApplication;
$this->phinx->setAutoExit(false);
$this->phinx->run(new StringInput('migrate'), new NullOutput);
$this->phinx->run(new StringInput('seed:run'), new NullOutput);
}
public function tearDown(){
$this->phinx->run(new StringInput('rollback -t 0'), new NullOutput);
}
这是我测试文件的代码,每次我添加
public function testExampleFunction(){
$this->assertTrue(true);
}
在线失败:
$this->phinx->run(new StringInput('rollback -t 0'), new NullOutput);
错误:
Fatal error: Call to a member function run() on null in {path to the test file}
当我改变这个时:
public function tearDown()
{
if (!empty($this->phinx)) {
$this->phinx->run(new StringInput('rollback -t 0'), new NullOutput);
}
}
它通过了,但是由于没有回滚,我的下一个测试崩溃了
您使用的是命名空间 (PSR-4) 吗? 如果是这样,你应该有这行代码:
use Phinx\Console\PhinxApplication;