I want to delete every new entry made with the tests in order to make it possible to run it again (both on the CI build or manually) without having to manually delete the database entries made with the previous run of the tests. I have found the tearDown() and tearDownAfterClass() but it seems to be useful only for connecting/disconnecting the link with the database. Can I use it to delete the entries made with the tests?
Yes, you can do it via the methods you mentioned.
tearDown method is enabled after every single test inside the classtearDownAfterClass method is enabled at the end of all tests inside the classI would suggest you use a rollback pattern, so
setUp method you would initialize the transaction protected function setUp(): void
{
//...some boilerplate with establish connection
$this->connection->beginTransaction();
}
tearDown method you would rolling back changes made in tests protected function tearDown(): void
{
$this->connection->rollback();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With