1
0
mirror of synced 2025-02-09 08:49:26 +03:00

Register custom types to not skip model set validation

Also removing an empty and unused model set.
This commit is contained in:
Luís Cobucci 2017-05-31 08:22:55 +02:00
parent ee5f222c58
commit a9c711ad7e
No known key found for this signature in database
GPG Key ID: EC61C5F01750ED3C
2 changed files with 40 additions and 10 deletions

View File

@ -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));
}
}
}

View File

@ -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,