1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
<?php
declare(strict_types=1);
namespace Doctrine\Tests\ORM\Functional;
use Doctrine\DBAL\Exception as DBALException;
use Doctrine\DBAL\Types\Type as DBALType;
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 PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
use function array_keys;
use function constant;
use function implode;
/**
* Test the validity of all modelsets
*/
#[Group('DDC-1601')]
class SchemaValidatorTest extends OrmFunctionalTestCase
{
protected function setUp(): void
{
$this->registerType(CustomIdObjectType::class);
$this->registerType(UpperCaseStringType::class);
$this->registerType(NegativeToPositiveType::class);
parent::setUp();
}
/** @throws DBALException */
private function registerType(string $className): void
{
$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): void
{
$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);
self::assertEmpty($ce, 'Invalid Modelset: ' . $modelSet . ' class ' . $class->name . ': ' . implode("\n", $ce));
}
}
}
|