Completed
Pull Request — master (#6481)
by Luís
17:57 queued 05:46
created

SchemaValidatorTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
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()
41
    {
42
        $modelSets = [];
43
44
        foreach (self::$_modelSets as $modelSet => $classes) {
45
            $modelSets[] = [$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->assertCount(0, $ce, "Invalid Modelset: " . $modelSet . " class " . $class->name . ": ". implode("\n", $ce));
67
        }
68
69
        if (empty($classes)) {
70
            $this->addToAssertionCount(1);
71
        }
72
    }
73
}
74