Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace AppBundle\Tests;
- use Doctrine\DBAL\Connection;
- use Doctrine\ORM\Tools\SchemaTool;
- use Doctrine\DBAL\Driver\PDOMysql\Driver as MySQLDriver;
- class DoctrineMigrationTest extends WebTestCase
- {
- protected function setUp()
- {
- // Since I use LiipFunctionalTestBundle I usually use SQLite for my functional tests
- // so I setup a 2nd environment for testing the Migrations with the actual target DB.
- // Note this environment uses a dedicated schema (ie. my_db vs my_db_test)
- $this->environment = 'mysql_test';
- /* @var \Doctrine\ORM\EntityManager */
- $em = $this->getContainer()->get('doctrine')->getManager();
- /** @var Connection $connection */
- $connection = $em->getConnection();
- $driver = $connection->getDriver();
- if (!$driver instanceof MySQLDriver) {
- $this->markTestSkipped('This test requires MySQL.');
- }
- try {
- $databaseName = $this->getContainer()->getParameter('database_name');
- if (in_array($databaseName, $connection->getSchemaManager()->listDatabases())) {
- $schemaTool = new SchemaTool($em);
- // Drop all tables, so we can test on a clean DB
- $schemaTool->dropDatabase();
- }
- } catch (\Exception $e) {
- $this->fail('Could not cleanup test database for migration test: ' . $e->getMessage());
- }
- }
- /**
- * @group mysql
- */
- public function testMigrations()
- {
- // Test if all migrations run through
- $output = $this->runCommand('doctrine:migrations:migrate', ['--no-interaction']);
- $this->assertRegExp('/\d+ sql queries\n$/', $output);
- // Validate that the mapping files are correct and in sync with the database.
- $output = $this->runCommand('doctrine:schema:validate');
- $this->assertContains('[Mapping] OK - The mapping files are correct.', $output);
- $this->assertContains('[Database] OK - The database schema is in sync with the mapping files.', $output);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement