Completed
Push — master ( 3dc0f4...fc67b3 )
by Marco
22s
created

SchemaValidatorTest::registerType()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 1
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
    /**
29
     * @param string $className
30
     *
31
     * @throws \Doctrine\DBAL\DBALException
32
     *
33
     * @return void
34
     */
35
    private function registerType(string $className)
36
    {
37
        $type = constant($className . '::NAME');
38
39
        if (DBALType::hasType($type)) {
40
            DBALType::overrideType($type, $className);
41
            return;
42
        }
43
44
        DBALType::addType($type, $className);
45
    }
46
47
    public static function dataValidateModelSets(): array
48
    {
49
        $modelSets = [];
50
51
        foreach (array_keys(self::$_modelSets) as $modelSet) {
52
            $modelSets[$modelSet] = [$modelSet];
53
        }
54
55
        return $modelSets;
56
    }
57
58
    /**
59
     * @dataProvider dataValidateModelSets
60
     */
61
    public function testValidateModelSets(string $modelSet)
62
    {
63
        $validator = new SchemaValidator($this->_em);
64
        $classes   = [];
65
66
        foreach (self::$_modelSets[$modelSet] as $className) {
67
            $classes[] = $this->_em->getClassMetadata($className);
68
        }
69
70
        foreach ($classes as $class) {
71
            $ce = $validator->validateClass($class);
72
73
            $this->assertEmpty($ce, "Invalid Modelset: " . $modelSet . " class " . $class->name . ": ". implode("\n", $ce));
74
        }
75
    }
76
}
77