mardi 31 janvier 2017

Fixtures deleted after being generated by exec() function

I am working on a big Symfony2 project on which there is two kinds of test classes. Those where we expect the data to be manipulated, and those where the data should not be manipulated (due to credential insuffisance).

In this second kind of test classes I am trying to implement a public static function setUpBeforeClass() method in which the fixtures will be loaded once for all in my test class.

However, in order to do so, the only way I found is to :

  1. Create a "test classes" that only generate fixtures, like so :

    class ResetFixturesTest extends WebTestCase{
          public function testResetFixtures(){   
               $this->loadFixtures(array(
                    "Path\\to\\my\\fixtures\\classes"
               ));
          }
    }
    
    

    Note that I did not implement the $this->loadFixtures() function, it was created by a former employee. So I kinda "must" use this way of generating fixtures.

  2. I create my SetUpBeforeClass() function in DummyClassTest like this :

    public static function setUpBeforeClass() {
        parent::setUpBeforeClass();
        $process = new Process('phpunit -c app/ --filter testResetFixedFixtures');
        $process->run();
    }
    
    

Then I can launch my test class.

The problem is : When I launch my test class, lets say : phpunit -c app/ --filter DummyClassTest, my fixtures are first properly generated, from the setUpBeforeClass() method, but then, when it actually starts my tests from DummyClass, my fixtures disapears from my database. And so I get an error, because I need users from my database.

How can I solve that ?

Thank you.

Aucun commentaire:

Enregistrer un commentaire