From a9c711ad7ea25f9eec286d0054d78299b9e82e8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Wed, 31 May 2017 08:22:55 +0200 Subject: [PATCH] Register custom types to not skip model set validation Also removing an empty and unused model set. --- .../ORM/Functional/SchemaValidatorTest.php | 49 +++++++++++++++---- .../Doctrine/Tests/OrmFunctionalTestCase.php | 1 - 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/SchemaValidatorTest.php b/tests/Doctrine/Tests/ORM/Functional/SchemaValidatorTest.php index d6f98af1f..5ab0f07c0 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SchemaValidatorTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SchemaValidatorTest.php @@ -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)); } } } diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index 2a5f45264..e9299b1c6 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -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,