For symfony2 functional testing, what is the best practice for validating database content?

I see that there are several ways to load instrument data into a database. But after a functional test, is the correct or standard way of confirming what was written to the database correct?

The phpunit package has a whole section for this, where you can load the dataset and then use things like assertTablesEqual () to compare the contents of the table with the expected contents. But this is not like using Symfony2, and I cannot find any other standard method.

How do others solve this problem?

+5
source share
2 answers

Symfony2 uses the ORM doctrine by default, or you can install another database gestion (MongoDB, for example). Check the file app\config\parameters.php to establish a connection to the database and app\config\config.php to check / set the type of gestion. With ORM you do not need to check many things like phpunit package, because it is already integrated into protocole and much more. Read more here .

If you want to load datafixtures , you can export your actual database to save it or create a new one just for testing and switching the database in app\config\parameters.php , creating a new one like this app\config\parameters_dev.php . In this case, the website and your local version will not use the same database. You can also edit app\config\parameters.php and prevent it with the .gitgnore file.

+1
source

Here is an example from a test suite that includes database results. If you need to interact directly with the database in your test, the object manager may be available for testing. See this bit of documentation for more information. Note that the results are most often displayed on a web page and read by the DOM crawler.

 public function setUp() { self::bootKernel(); $this->em = static::$kernel->getContainer() ->get('doctrine') ->getManager() ; $this->tool = static::$kernel->getContainer() ->get('truckee.toolbox') ; $classes = array( 'Truckee\VolunteerBundle\DataFixtures\SampleData\LoadFocusSkillData', 'Truckee\VolunteerBundle\DataFixtures\SampleData\LoadMinimumData', 'Truckee\VolunteerBundle\DataFixtures\SampleData\LoadStaffUserGlenshire', 'Truckee\VolunteerBundle\DataFixtures\SampleData\LoadStaffUserMelanzane', 'Truckee\VolunteerBundle\DataFixtures\SampleData\LoadOpportunity', 'Truckee\VolunteerBundle\DataFixtures\SampleData\LoadVolunteer', ); $this->loadFixtures($classes); $this->client = $this->createClient(); $this->client->followRedirects(); } public function testOutboxUser() { $crawler = $this->login('admin'); $link = $crawler->selectLink("Send alerts to organizations")->link(); $crawler = $this->client->click($link); $outboxObj = $this->em->getRepository('TruckeeVolunteerBundle:AdminOutbox')->findAll(); $outbox = $outboxObj[0]; $recipient = $outbox->getRecipientId(); $type = $this->tool->getTypeFromId($recipient); $this->assertEquals('staff', $type); } 
0
source

Source: https://habr.com/ru/post/1235395/


All Articles