lundi 15 février 2021

symfony 4 - testing command against different data

I have a command which runs over the database, then tests if any companies have a duplicate name, then outputs to the user for any remediation.

What I want to do for each test is:

  • Change the database to prescribed set of companies, e.g. 10 companies with 5 of those having duplicate names or e.g. 10 companies with 5 having null names
  • Run that test

Normally if this was a function, I could use a data provider in the annotation to provide different data to test e.g.

     * @dataProvider provideFoo
     * @param $data
     */
    public function testFooBar($data) {...

But the command has no args/params, so I think I have to update the database each time.

Can this be done with fixtures, or should I add new companies in each test e.g.:

public function testFooBar($data) {
  $company1 = (new Company())->setName('Company 1');
  $this->entityManager->persist($company1);
  $this->entityManager->flush();
  
  $commandTester->execute([]);
  // rest of test
}

I should add - the db is quite large and dropping it and resetting it takes a few hours.

Aucun commentaire:

Enregistrer un commentaire