I am setting up Codeception for Api testing.
I have a Cest class, say...
class ZooCest {
public function addingALionToZoo(ApiTester $I)
{
$I->sendPost('zoo/add_animal', ['animal_id' => $animalId]);
}
}
The question is, where and how do I set up the data to test my api.
Following the previous example, I could do this:
class ZooCest {
public function addingALionToZoo(ApiTester $I)
{
$lion = new Animal('lion');
$lion->save();
$I->sendPost('zoo/add_animal', ['animal_id' => $lion->getId()]);
}
}
But this gets messy when business logic is complicated.
I could have a factorizer in the support folder, so I could so this:
class ZooCest {
public function addingALionToZoo(ApiTester $I)
{
$lion = DataFactory::create('lion');
$I->sendPost('zoo/add_animal', ['animal_id' => $lion->getId()]);
}
}
But that can grow a lot, becoming more and more complex as time passes, reaching a point in which we might even need testing for that logic! (yes, it's a joke)
Thanks.