Register custom types to not skip model set validation
Also removing an empty and unused model set.
This commit is contained in:
parent
ee5f222c58
commit
a9c711ad7e
@ -3,7 +3,11 @@
|
||||
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
|
||||
@ -12,26 +16,53 @@ use Doctrine\Tests\OrmFunctionalTestCase;
|
||||
*/
|
||||
class SchemaValidatorTest extends OrmFunctionalTestCase
|
||||
{
|
||||
static public function dataValidateModelSets()
|
||||
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 (self::$_modelSets as $modelSet => $classes) {
|
||||
if ($modelSet == "customtype") {
|
||||
continue;
|
||||
}
|
||||
$modelSets[] = [$modelSet];
|
||||
|
||||
foreach (array_keys(self::$_modelSets) as $modelSet) {
|
||||
$modelSets[$modelSet] = [$modelSet];
|
||||
}
|
||||
|
||||
return $modelSets;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataValidateModelSets
|
||||
*/
|
||||
public function testValidateModelSets($modelSet)
|
||||
public function testValidateModelSets(string $modelSet)
|
||||
{
|
||||
$validator = new SchemaValidator($this->_em);
|
||||
$classes = [];
|
||||
|
||||
$classes = [];
|
||||
foreach (self::$_modelSets[$modelSet] as $className) {
|
||||
$classes[] = $this->_em->getClassMetadata($className);
|
||||
}
|
||||
@ -39,7 +70,7 @@ class SchemaValidatorTest extends OrmFunctionalTestCase
|
||||
foreach ($classes as $class) {
|
||||
$ce = $validator->validateClass($class);
|
||||
|
||||
$this->assertEquals(0, count($ce), "Invalid Modelset: " . $modelSet . " class " . $class->name . ": ". implode("\n", $ce));
|
||||
$this->assertEmpty($ce, "Invalid Modelset: " . $modelSet . " class " . $class->name . ": ". implode("\n", $ce));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -106,7 +106,6 @@ abstract class OrmFunctionalTestCase extends OrmTestCase
|
||||
Models\CMS\CmsArticle::class,
|
||||
Models\CMS\CmsComment::class,
|
||||
],
|
||||
'forum' => [],
|
||||
'company' => [
|
||||
Models\Company\CompanyPerson::class,
|
||||
Models\Company\CompanyEmployee::class,
|
||||
|
Loading…
x
Reference in New Issue
Block a user