performance - Load fixtures one time before all phpunit test on symfony 3 -
i ve got sf3 application , lot of functionnals tests. before each tests load , purge fixtures. time of tests long. load fixtures 1 time et truncate after last test.
is method improve functionnal tests speed ?
is there php method in phpunit launched 1 time before tests ? (because setupbeforeclass executed before each test)
an exemple of setupbeforeclass method in test's classes.
class searchregistercontrollertest extends webtestcase { /** @var client $client */ private $client; protected static $application; public static function setupbeforeclass() { $kernel = static::createkernel(); $kernel->boot(); $em = $kernel->getcontainer()->get('doctrine.orm.entity_manager'); $schematool = new schematool($em); $metadata = $em->getmetadatafactory()->getallmetadata(); $schematool->dropschema($metadata); $schematool->createschema($metadata); /** @var client $client */ $client = static::createclient(); $em = $client->getcontainer()->get('doctrine.orm.entity_manager'); $loader = new loader(); $loader->loadfromdirectory('src/mynamespace/appbundle/datafixtures/orm'); $purger = new ormpurger(); $executor = new ormexecutor($em, $purger); $executor->execute($loader->getfixtures(), true); } thanks in advance.
you can use bash script load fixtures once before tests.
php bin/console doctrine:database:create --env=test --if-not-exists php bin/console doctrine:schema:update --force --env=test --complete php bin/console doctrine:fixtures:load --fixtures=tests/fixtures/api --env=test --no-interaction php vendor/bin/phpunit tests/functional keep in mind test not executed within isolated environments fresh data , interfere each other.
Comments
Post a Comment