Load fixtures one time before all phpunit test on symfony 3 Load fixtures one time before all phpunit test on symfony 3 symfony symfony

Load fixtures one time before all phpunit test on symfony 3


You could implement a test listener.

tests/StartTestSuiteListener.php

namespace App\Tests;class StartTestSuite extends \PHPUnit_Framework_BaseTestListener{    public function startTestSuite(\PHPUnit_Framework_TestSuite $suite)    {      // do initial stuff    }}

Then enable enable the test listener in your phpunit.xml config:

phpunit.xml

<phpunit ...>    <listeners>        <listener class="App\Tests\StartTestSuiteListener">        </listener>    </listeners>[...]</phpunit>

In the same manner you could implement a endTestSuite (Check for all event listed in the doc)

Hope this help


You can use bash script like this to load fixtures once before all tests.

php bin/console doctrine:database:create --env=test --if-not-existsphp bin/console doctrine:schema:update --force --env=test --completephp bin/console doctrine:fixtures:load --fixtures=tests/fixtures/api --env=test --no-interactionphp vendor/bin/phpunit tests/Functional

Keep in mind that your test will not be executed within isolated environments with fresh data and thus will interfere with each other.