Skip to content

Instantly share code, notes, and snippets.

@damienalexandre
Created October 9, 2015 10:17
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save damienalexandre/944e8856e223a6ea9063 to your computer and use it in GitHub Desktop.
Save damienalexandre/944e8856e223a6ea9063 to your computer and use it in GitHub Desktop.
Test doctrine schema automatically for missing / broken migrations.
<?php
namespace AppBundle\Tests;
use Doctrine\ORM\Tools\SchemaTool;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
/**
* Use Doctrine default entity manager and compare it's metadata to the actual database schema.
*
* @author dalexandre@jolicode.com
*/
class DatabaseSchemaTest extends KernelTestCase
{
protected function setUp()
{
self::bootKernel();
}
public function testSchemaIsUpToDate()
{
$em = static::$kernel->getContainer()->get('doctrine')->getManager();
$metadata = $em->getMetadataFactory()->getAllMetadata();
if (empty($metadata)) {
$this->markTestSkipped("No database mapping found.");
}
$schemaTool = new SchemaTool($em);
$sqls = $schemaTool->getUpdateSchemaSql($metadata, true);
$this->assertEmpty($sqls);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment