Welcome Guest, Not a member yet? Register   Sign In
Unit testing with database in CI 3.x
#1

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.
Reply
#2

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.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(03-15-2017, 03: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.
Reply
#4

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.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

(03-16-2017, 12: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
Reply
#6

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




Theme © iAndrew 2016 - Forum software by © MyBB