我正在使用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);
使用错误:
致命错误:在{path of the path中调用null上的成员函数run() 测试文件}
当我改变这个时:
public function tearDown()
{
if (!empty($this->phinx)) {
$this->phinx->run(new StringInput('rollback -t 0'), new NullOutput);
}
}
它通过但是由于没有回滚,我的下一个测试已经崩溃
答案 0 :(得分:2)
您使用的是命名空间(PSR-4)吗? 如果是这样,你应该有这行代码:
use Phinx\Console\PhinxApplication;