entityManager; } protected function setUp(): void { self::runCommand('doctrine:database:drop --force'); self::runCommand('doctrine:database:create'); self::runCommand('doctrine:schema:create'); self::runCommand('doctrine:fixtures:load --no-interaction'); $this->entityManager = static::createClient()->getContainer() ->get('doctrine') ->getManager(); parent::setUp(); } private static function runCommand($command) { $command = sprintf('%s --quiet', $command); return self::getApplication()->run(new StringInput($command)); } private static function getApplication() { if (self::$application === null) { $client = static::createClient(); self::$application = new Application($client->getKernel()); self::$application->setAutoExit(false); } return self::$application; } protected function tearDown(): void { self::runCommand('doctrine:database:drop --force'); parent::tearDown(); $this->entityManager->close(); $this->entityManager = null; // avoid memory leaks } }