PHPUnit and Doctrine: How to setup the database

894 views Asked by At

I'm trying to write some functional tests for a Symfony2 app. Those tests interacts with the database, using, obviously, Doctrine.

Now, I setup the configuration to call the test database, but it is empty and has no tables, so my tests fail.

How can I build the database schema into the test database before the execution of the tests?

I have tried this

namespace AppBundle\Tests\Controller;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class GetStartedControllerTest extends WebTestCase
{
    public function setUp()
    {
        passthru(sprintf('php "%s/console" cache:clear --env=test --no-warmup --no-interaction', __DIR__));
        passthru(sprintf('php "%s/console" doctrine:database:drop --env=test --force --no-interaction', __DIR__));
        passthru(sprintf('php "%s/console" doctrine:database:create --env=test --no-interaction', __DIR__));
        passthru(sprintf('php "%s/console" doctrine:schema:update --force --env=test --no-interaction', __DIR__));
    }

    /**
     *
     */
    public function testRegisterNewUser()
    {

    ...

But it seems not working...

Any ideas? Thank you!

0

There are 0 answers