php - Setting up functional tests with custom database data in Symfony -


for sake of simplicity, let's have schema.

a machine, site , user associated task. task can have many (say @ least twenty) different taskdetail's.

task  task_id (int pk) machine_id (int fk) user_id (int fk) site_id (int fk) task_name (varchar) task_time (int)  taskdetail  task_detail_id (int pk) task_id (int fk) task_detail_value (varchar)  machine  machine_id (int pk) machine_name (varchar)  user  user_id (int pk) user_name (varchar) user_register_time (int)  site  site_id (int pk) site_name (varchar) 

how can best populate test data symfony? using phpunit testing framework.

i have written functional tests in symfony before, never test data database. it's been limited simpler tests (does dropdown menu have following items in it, etc).

so example, on list of tasks page - wanted test 5 tasks appear. how set test such i'd populate database 5 tasks (that imagine need hard code somewhere?), test output of page shows 5 tasks created?

i've looked @ http://symfony.com/doc/current/cookbook/testing/database.html , few other pages , i've yet find outlines how asking - , seems simple test case me.

so pointers welcome. thanks.

have @ doctrine fixtures, allow load controlled data sets database testing or make sure have initial data.

symfony2 has integration doctrine fixtures through doctrinefixturesbundle.

write fixtures entities needed make sure there enough data tests . can load fixtures using console command bundle offers. can functional testing usual.

also follow these articles unit test code interacts database.

http://symfony.com/doc/current/cookbook/testing/database.html

http://symfony.com/doc/current/cookbook/testing/doctrine.html


Comments