2012-01-15 11:27:28 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Doctrine\Tests\ORM\Functional;
|
|
|
|
|
|
|
|
use Doctrine\ORM\Tools\SchemaValidator;
|
2017-05-31 08:22:55 +02:00
|
|
|
use Doctrine\Tests\DbalTypes\CustomIdObjectType;
|
|
|
|
use Doctrine\Tests\DbalTypes\NegativeToPositiveType;
|
|
|
|
use Doctrine\Tests\DbalTypes\UpperCaseStringType;
|
2016-05-11 02:41:26 +07:00
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase;
|
2017-05-31 08:22:55 +02:00
|
|
|
use Doctrine\DBAL\Types\Type as DBALType;
|
2012-01-15 11:27:28 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the validity of all modelsets
|
|
|
|
*
|
|
|
|
* @group DDC-1601
|
|
|
|
*/
|
2016-05-11 02:41:26 +07:00
|
|
|
class SchemaValidatorTest extends OrmFunctionalTestCase
|
2012-01-15 11:27:28 +01:00
|
|
|
{
|
2017-05-31 08:22:55 +02:00
|
|
|
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
|
2012-01-15 11:27:28 +01:00
|
|
|
{
|
2016-12-07 23:33:41 +01:00
|
|
|
$modelSets = [];
|
2017-05-31 08:22:55 +02:00
|
|
|
|
|
|
|
foreach (array_keys(self::$_modelSets) as $modelSet) {
|
|
|
|
$modelSets[$modelSet] = [$modelSet];
|
2012-01-15 11:27:28 +01:00
|
|
|
}
|
2017-05-31 08:22:55 +02:00
|
|
|
|
2012-01-15 11:27:28 +01:00
|
|
|
return $modelSets;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider dataValidateModelSets
|
|
|
|
*/
|
2017-05-31 08:22:55 +02:00
|
|
|
public function testValidateModelSets(string $modelSet)
|
2012-01-15 11:27:28 +01:00
|
|
|
{
|
|
|
|
$validator = new SchemaValidator($this->_em);
|
2017-05-31 08:22:55 +02:00
|
|
|
$classes = [];
|
2012-01-15 11:27:28 +01:00
|
|
|
|
|
|
|
foreach (self::$_modelSets[$modelSet] as $className) {
|
|
|
|
$classes[] = $this->_em->getClassMetadata($className);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($classes as $class) {
|
|
|
|
$ce = $validator->validateClass($class);
|
|
|
|
|
2017-05-31 08:22:55 +02:00
|
|
|
$this->assertEmpty($ce, "Invalid Modelset: " . $modelSet . " class " . $class->name . ": ". implode("\n", $ce));
|
2012-01-15 11:27:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|