Passed
Pull Request — master (#212)
by David
09:14
created

TDBMSchemaAnalyzerTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Importance

Changes 4
Bugs 1 Features 1
Metric Value
wmc 5
eloc 24
c 4
b 1
f 1
dl 0
loc 65
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A testGetIncomingForeignKeys2() 0 8 1
A testGetPivotTableLinkedToTable() 0 15 1
A testGetIncomingForeignKeys3() 0 13 1
A testGetIncomingForeignKeys() 0 8 1
1
<?php
2
declare(strict_types=1);
3
4
/*
5
 Copyright (C) 2006-2014 David Négrier - THE CODING MACHINE
6
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2 of the License, or
10
(at your option) any later version.
11
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
GNU General Public License for more details.
16
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20
*/
21
22
namespace TheCodingMachine\TDBM;
23
24
use Doctrine\Common\Cache\ArrayCache;
25
use Mouf\Database\SchemaAnalyzer\SchemaAnalyzer;
26
use TheCodingMachine\TDBM\Utils\ImmutableCaster;
27
28
class TDBMSchemaAnalyzerTest extends TDBMAbstractServiceTest
29
{
30
    /**
31
     * @var TDBMSchemaAnalyzer
32
     */
33
    protected $tdbmSchemaAnalyzer;
34
35
    protected function setUp(): void
36
    {
37
        parent::setUp();
38
        $schemaAnalyzer = new SchemaAnalyzer(self::getConnection()->getSchemaManager(), new ArrayCache(), 'prefix_');
39
        $schemaLockFileDumper = new SchemaLockFileDumper(self::getConnection(), new ArrayCache(), Configuration::getDefaultLockFilePath());
40
        $this->tdbmSchemaAnalyzer = new TDBMSchemaAnalyzer(self::getConnection(), new ArrayCache(), $schemaAnalyzer, $schemaLockFileDumper);
41
    }
42
43
    public function testGetIncomingForeignKeys(): void
44
    {
45
        /*$schemaAnalyzer = new SchemaAnalyzer(self::getConnection()->getSchemaManager(), new ArrayCache(), 'prefix_');
46
        $cache = new ArrayCache();
47
        $tdbmSchemaAnalyzer = new TDBMSchemaAnalyzer(self::getConnection(), $cache, $schemaAnalyzer, Configuration::getDefaultLockFilePath());*/
48
49
        $fks = $this->tdbmSchemaAnalyzer->getIncomingForeignKeys('users');
50
        $this->assertCount(1, $fks);
51
    }
52
53
    public function testGetIncomingForeignKeys2(): void
54
    {
55
        /*$schemaAnalyzer = new SchemaAnalyzer(self::getConnection()->getSchemaManager(), new ArrayCache(), 'prefix_');
56
        $cache = new ArrayCache();
57
        $tdbmSchemaAnalyzer = new TDBMSchemaAnalyzer(self::getConnection(), $cache, $schemaAnalyzer, Configuration::getDefaultLockFilePath());*/
58
59
        $fks = $this->tdbmSchemaAnalyzer->getIncomingForeignKeys('contact');
60
        $this->assertCount(1, $fks);
61
    }
62
63
    public function testGetIncomingForeignKeys3(): void
64
    {
65
        /*$schemaAnalyzer = new SchemaAnalyzer(self::getConnection()->getSchemaManager(), new ArrayCache(), 'prefix_');
66
        $cache = new ArrayCache();
67
        $tdbmSchemaAnalyzer = new TDBMSchemaAnalyzer(self::getConnection(), $cache, $schemaAnalyzer, Configuration::getDefaultLockFilePath());*/
68
69
        $fks = $this->tdbmSchemaAnalyzer->getIncomingForeignKeys('country');
70
        $this->assertCount(5, $fks);
71
        $tables = [$fks[0]->getLocalTableName(), $fks[1]->getLocalTableName(), $fks[2]->getLocalTableName(), $fks[3]->getLocalTableName(), $fks[4]->getLocalTableName()];
72
        $this->assertContains('users', $tables);
73
        $this->assertContains('all_nullable', $tables);
74
        $this->assertContains('boats', $tables);
75
        $this->assertContains('states', $tables);
76
    }
77
78
    public function testGetPivotTableLinkedToTable(): void
79
    {
80
        /*$schemaAnalyzer = new SchemaAnalyzer(self::getConnection()->getSchemaManager(), new ArrayCache(), 'prefix_');
81
        $cache = new ArrayCache();
82
        $tdbmSchemaAnalyzer = new TDBMSchemaAnalyzer(self::getConnection(), $cache, $schemaAnalyzer, Configuration::getDefaultLockFilePath());*/
83
84
        $pivotTables = $this->tdbmSchemaAnalyzer->getPivotTableLinkedToTable('rights');
85
        $this->assertCount(1, $pivotTables);
86
        $this->assertEquals('roles_rights', $pivotTables[0]);
87
88
        $pivotTables = $this->tdbmSchemaAnalyzer->getPivotTableLinkedToTable('animal');
89
        $this->assertCount(0, $pivotTables);
90
91
        $pivotTables = $this->tdbmSchemaAnalyzer->getPivotTableLinkedToTable('animal');
92
        $this->assertCount(0, $pivotTables);
93
    }
94
95
    /*public function testGetCompulsoryColumnsWithNoInheritance() {
96
        $table = $this->tdbmSchemaAnalyzer->getSchema()->getTable('country');
97
        $compulsoryColumns = $this->tdbmSchemaAnalyzer->getCompulsoryProperties($table);
98
        $this->assertCount(1, $compulsoryColumns);
99
        $this->assertArrayHasKey("label", $compulsoryColumns);
100
    }
101
102
    public function testGetCompulsoryColumnsWithInheritance() {
103
        $table = $this->tdbmSchemaAnalyzer->getSchema()->getTable('users');
104
        $compulsoryColumns = $this->tdbmSchemaAnalyzer->getCompulsoryProperties($table);
105
        $this->assertCount(5, $compulsoryColumns);
106
        $this->assertEquals(['name', 'created_at', 'email', 'country_id', 'login'], array_keys($compulsoryColumns));
107
    }*/
108
}
109