3

我正在使用 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 to the test file} 中调用 null 上的成员函数 run()

当我改变这个:

 public function tearDown()
    {

        if (!empty($this->phinx)) {
            $this->phinx->run(new StringInput('rollback -t 0'), new NullOutput);
        }

    } 

它通过了,但由于没有回滚,我的下一个测试已经崩溃

4

1 回答 1

2

你在使用命名空间 (PSR-4) 吗?如果是这样,你应该有这行代码:

use Phinx\Console\PhinxApplication;

于 2017-11-16T15:03:19.630 回答