3

I know that there are a lot of similar questions (Codeception & Symfony - run Doctrine migrations before tests) but do I really need to run migrations in tests like exec(...) or there is a better way for doing that?

Another thing: when I try to run migrations for sqlite db i get an error message: Migration can only be executed safely on mysql

Jakub Saleniuk
  • 405
  • 5
  • 15
  • 1
    About the message, in you migration file you got this line: `$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');` If you are sure the migration can be run on other platforms, you can remove this line – Perry May 07 '18 at 09:13

2 Answers2

1

Here is my working code sf 6.0. Simply implement.

abstract class AbtractWithMigrationTestCase extends KernelTestCase
{
    protected function setUp(): void
    {
        $kernel = self::bootKernel(['environment' => 'test']);
        $application = new Application($kernel);
        $command = $application->find('doctrine:migrations:migrate');
        $commandTester = new CommandTester($command);
        $commandTester->execute(['n']);
    }
}
Xmanoux
  • 3,435
  • 4
  • 15
  • 16
  • For database configuration, set a .env.test, where you configure a mysql database. (Mysql migrations queries with SQLite will fail). I have set a docker mysql server mounted on ramfs and it's blazing fast. – Xmanoux Jan 30 '23 at 21:30
0

you can type in your console :

php bin/console doctrine:schema:update --dumpsql (to check the whole request) php bin/console doctrine:schema:update --force (to execute the request)

source : https://symfony.com/doc/3.4/doctrine.html (works in Symfony 4)

André
  • 1