Completed
Pull Request — master (#6481)
by Luís
15:39
created

SchemaValidatorTest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 4
dl 0
loc 57
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 8 1
A registerType() 0 11 2
A dataValidateModelSets() 0 10 2
A testValidateModelSets() 0 19 4
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