What architecture pattern are you using for the generation of test data on a test function that first generates test data, then does a functional api test and afterwards asserts some result?
public function test_it_returns_not_found_when_book_doesnt_exist(){
// data generation
$account = new Account();
$account->setName("Test");
$account->save();
$user = new User();
$user->setEmail("test@test.de");
$user->setAccount($account);
$user->save();
// request
$this->client->init("api.example.com");
$this->client->login($user);
$res = $this->client->request("GET","/books/1");
// assertion
$this->assertEquals(404, $res->getStatusCode());
}
I would like to have the data generation as reusable and flexible as possible. It should also have default values and be overwritten if needed by the developer that writes the test function. In some cases we need only a certain amount of elements in e.g. in 1:n relation in others we need very specific rows.
Aucun commentaire:
Enregistrer un commentaire