|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\ORM\Functional; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\ORM\Tools\SchemaValidator; |
|
6
|
|
|
use Doctrine\Tests\DbalTypes\CustomIdObjectType; |
|
7
|
|
|
use Doctrine\Tests\DbalTypes\NegativeToPositiveType; |
|
8
|
|
|
use Doctrine\Tests\DbalTypes\UpperCaseStringType; |
|
9
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase; |
|
10
|
|
|
use Doctrine\DBAL\Types\Type as DBALType; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Test the validity of all modelsets |
|
14
|
|
|
* |
|
15
|
|
|
* @group DDC-1601 |
|
16
|
|
|
*/ |
|
17
|
|
|
class SchemaValidatorTest extends OrmFunctionalTestCase |
|
18
|
|
|
{ |
|
19
|
|
|
protected function setUp() |
|
20
|
|
|
{ |
|
21
|
|
|
$this->registerType(CustomIdObjectType::class); |
|
22
|
|
|
$this->registerType(UpperCaseStringType::class); |
|
23
|
|
|
$this->registerType(NegativeToPositiveType::class); |
|
24
|
|
|
|
|
25
|
|
|
parent::setUp(); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
private function registerType(string $className) |
|
29
|
|
|
{ |
|
30
|
|
|
$type = constant($className . '::NAME'); |
|
31
|
|
|
|
|
32
|
|
|
if (DBALType::hasType($type)) { |
|
33
|
|
|
DBALType::overrideType($type, $className); |
|
34
|
|
|
return; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
DBALType::addType($type, $className); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public static function dataValidateModelSets(): array |
|
41
|
|
|
{ |
|
42
|
|
|
$modelSets = []; |
|
43
|
|
|
|
|
44
|
|
|
foreach (array_keys(self::$_modelSets) as $modelSet) { |
|
45
|
|
|
$modelSets[$modelSet] = [$modelSet]; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
return $modelSets; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @dataProvider dataValidateModelSets |
|
53
|
|
|
*/ |
|
54
|
|
|
public function testValidateModelSets(string $modelSet) |
|
55
|
|
|
{ |
|
56
|
|
|
$validator = new SchemaValidator($this->_em); |
|
57
|
|
|
$classes = []; |
|
58
|
|
|
|
|
59
|
|
|
foreach (self::$_modelSets[$modelSet] as $className) { |
|
60
|
|
|
$classes[] = $this->_em->getClassMetadata($className); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
foreach ($classes as $class) { |
|
64
|
|
|
$ce = $validator->validateClass($class); |
|
65
|
|
|
|
|
66
|
|
|
$this->assertEmpty($ce, "Invalid Modelset: " . $modelSet . " class " . $class->name . ": ". implode("\n", $ce)); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|