vendredi 31 juillet 2015

symfony2 phpunit : how to drop and copy database before running tests?

In my symfony2 application, I am using phpunit to verify that the response from every route has a code 200.

Before I run the tests, I want to drop the test database and copy my production database under the name test (i.e. I want to reinitiate my test database).

I learned about the public static function setUpBeforeClass() but I am lost as to how drop and copy the database.

How can I do that ?

My class so far :

<?php

namespace AppBundle\Tests\Controller;

use AppBundle\FoodMeUpParameters;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

require_once __DIR__.'/../../../../app/AppKernel.php';


class ApplicationAvailabilityFunctionalTest extends WebTestCase
{

    public static function setUpBeforeClass()
    {

    }

    /**
     * @dataProvider routeProvider
     * @param $route
     */
    public function testAllRoutesAreLoaded($route)
    {
        $listedRoutes = $this->getListedRoutes();

        $this->assertArrayHasKey($route, $listedRoutes);
    }
}

Aucun commentaire:

Enregistrer un commentaire