Skip to content

Instantly share code, notes, and snippets.

@mnapoli
Created December 10, 2012 09:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mnapoli/4249675 to your computer and use it in GitHub Desktop.
Save mnapoli/4249675 to your computer and use it in GitHub Desktop.
Doctrine schema validation in a PHPUnit test
<?php
/**
* @author Matthieu Napoli
* @link http://en.mnapoli.fr/doctrine-schema-validation-in-a-phpunit-test/
* @license WTFPL - Do What The Fuck You Want To Public License (http://sam.zoy.org/wtfpl/)
*/
use Doctrine\ORM\Tools\SchemaValidator;
/**
* Doctrine schema validation
*/
class SchemaValidationTest extends PHPUnit_Framework_TestCase
{
/**
* @var \Doctrine\ORM\EntityManager
*/
protected $entityManager;
public function setUp() {
$this->entityManager = /* inject your entity manager here */;
}
public function testValidateSchema() {
$validator = new SchemaValidator($this->entityManager);
$errors = $validator->validateMapping();
if (count($errors) > 0) {
$message = PHP_EOL;
foreach ($errors as $class => $classErrors) {
$message .= "- " . $class . ":" . PHP_EOL . implode(PHP_EOL, $classErrors) . PHP_EOL . PHP_EOL;
}
$this->fail($message);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment