3

I am using PHPUnit 5.7.23 and 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);

}

This it the code of my test file , every time when i add

 public function testExampleFunction(){


        $this->assertTrue(true);
    }

it fails on the line :

$this->phinx->run(new StringInput('rollback -t 0'), new NullOutput);

with the errror :

Fatal error: Call to a member function run() on null in {path to the test file}

when i change this:

 public function tearDown()
    {

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

    } 

it passes but since there wasn't rollback, my next tests had crashed

Jozef Barca
  • 160
  • 2
  • 12
  • *$this->phinx* seems to be *null*, like not properly initialised as instance of *PhinxApplication*. Can you please debug if the *setup* was called before your *tearDown()* method? – BenRoob Nov 16 '17 at 08:39
  • yeah it is called before the tearDown() and it even completes : `$this->phinx->run(new StringInput('migrate'), new NullOutput); $this->phinx->run(new StringInput('seed:run'), new NullOutput);` – Jozef Barca Nov 16 '17 at 08:42
  • just to add that it works for other tests configured the same way, just in this test it fails – Jozef Barca Nov 16 '17 at 08:44

1 Answers1

2

Are you using namespacing (PSR-4) ? If so, you should have this line of code:

use Phinx\Console\PhinxApplication;

EmJam
  • 68
  • 6