How to append fixtures in liip functional test (symfony 2.8)? How to append fixtures in liip functional test (symfony 2.8)? symfony symfony

How to append fixtures in liip functional test (symfony 2.8)?


The only solution to avoid having the database purged is to create a testing database. To do that, below are the steps:

config of a testing database

# the config has to be done in config_test.ymldoctrine:    dbal:        default_connection: default        connections:            default:                driver:   pdo_mysql                host:     "%database_host%"                port:     "%database_port%"                dbname:   test                user:     "%database_user%"                password: "%database_password%"                charset:  UTF8

creation of the database and the tables

// this command is run only once (just for creating the testing db)$ php app/console doctrine:database:create --env=test// this command is needed when you have new entities$ php app/console doctrine:schema:create --env=test

How to load fixtures in the test?

    $fixtures = array('Minn\APIBundle\Tests\Fixtures\Entity\LoadBrandData');    $this->loadFixtures($fixtures);    $brands = LoadBrandData::$brands;

Hope it will help others!


It is possible to use a SQLite database for functional testing. See the docs for details on the bundle's configuration. If, for example, you are using MySQL it is pretty straightforward to create a database in the test environment with

$ php app/console doctrine:database:create --env=test$ php app/console doctrine:schema:create --env=test

and have the same behavior in the test environment as in the dev environment.

Your fixtures should load readily.

Edit:in config_test.yml:

doctrine:    dbal:        driver:   pdo_mysql        host:     localhost        port:     3306        dbname:   minnapi_test        user:     "%database_user%"        password: "%database_password%"

Copy .../web/app_dev.php to .../web/app_test.php and modify one line to read $kernel = new AppKernel('test', true);