Created
December 10, 2012 09:56
-
-
Save mnapoli/4249675 to your computer and use it in GitHub Desktop.
Doctrine schema validation in a PHPUnit test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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