1
0
mirror of synced 2025-02-03 22:09:26 +03:00
doctrine2/tests/Doctrine/Tests/ORM/Functional/SchemaValidatorTest.php
Luís Cobucci a9c711ad7e
Register custom types to not skip model set validation
Also removing an empty and unused model set.
2017-06-12 23:05:57 +02:00

77 lines
1.9 KiB
PHP

<?php
namespace Doctrine\Tests\ORM\Functional;
use Doctrine\ORM\Tools\SchemaValidator;
use Doctrine\Tests\DbalTypes\CustomIdObjectType;
use Doctrine\Tests\DbalTypes\NegativeToPositiveType;
use Doctrine\Tests\DbalTypes\UpperCaseStringType;
use Doctrine\Tests\OrmFunctionalTestCase;
use Doctrine\DBAL\Types\Type as DBALType;
/**
* Test the validity of all modelsets
*
* @group DDC-1601
*/
class SchemaValidatorTest extends OrmFunctionalTestCase
{
protected function setUp()
{
$this->registerType(CustomIdObjectType::class);
$this->registerType(UpperCaseStringType::class);
$this->registerType(NegativeToPositiveType::class);
parent::setUp();
}
/**
* @param string $className
*
* @throws \Doctrine\DBAL\DBALException
*
* @return void
*/
private function registerType(string $className)
{
$type = constant($className . '::NAME');
if (DBALType::hasType($type)) {
DBALType::overrideType($type, $className);
return;
}
DBALType::addType($type, $className);
}
public static function dataValidateModelSets(): array
{
$modelSets = [];
foreach (array_keys(self::$_modelSets) as $modelSet) {
$modelSets[$modelSet] = [$modelSet];
}
return $modelSets;
}
/**
* @dataProvider dataValidateModelSets
*/
public function testValidateModelSets(string $modelSet)
{
$validator = new SchemaValidator($this->_em);
$classes = [];
foreach (self::$_modelSets[$modelSet] as $className) {
$classes[] = $this->_em->getClassMetadata($className);
}
foreach ($classes as $class) {
$ce = $validator->validateClass($class);
$this->assertEmpty($ce, "Invalid Modelset: " . $modelSet . " class " . $class->name . ": ". implode("\n", $ce));
}
}
}