CodeIgniter Forums

Full Version: Unit testing with database in CI 3.x
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello all,

I have started writing Unit tests for an existing application. I am testing with database. I wanted to know if is there a way reinitialize MySQL back to its state before running the test. What am looking for is suggestions and resources. Thanks all.
What do you mean by reinitialize MySQL Database?

Back to an empty database or what?

If it's back to an empty database then all you need to do is delete all the tables.
(03-15-2017, 04:07 PM)InsiteFX Wrote: [ -> ]What do you mean by reinitialize MySQL Database?

Back to an empty database or what?

If it's back to an empty database then all you need to do is delete all the tables.

Sorry for the misunderstanding. I meant that I have a database at a certain state. I am testing my models, and some tests insert and delete info from the database, I want the database to go back to the state it was before running the tests.
You would need to make an sql dump of the normal state then delete all tables and run the sql dump to put it back.

You can do this using CodeIgniter Query Builder.
(03-16-2017, 01:29 PM)InsiteFX Wrote: [ -> ]You would need to make an sql dump of the normal state then delete all tables and run the sql dump to put it back.

You can do this using CodeIgniter Query Builder.

Thank you
If you use ci-phpunit-test, it provides sample database seeders.
See https://github.com/kenjis/ci-phpunit-tes...se-seeding