Passed
Pull Request — master (#212)
by David
03:32 queued 37s
created

testGetPivotTableLinkedToTable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
c 0
b 0
f 0
dl 0
loc 11
rs 10
cc 1
nc 1
nop 0
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
        $fks = $this->tdbmSchemaAnalyzer->getIncomingForeignKeys('users');
46
        $this->assertCount(1, $fks);
47
    }
48
49
    public function testGetIncomingForeignKeys2(): void
50
    {
51
        $fks = $this->tdbmSchemaAnalyzer->getIncomingForeignKeys('contact');
52
        $this->assertCount(1, $fks);
53
    }
54
55
    public function testGetIncomingForeignKeys3(): void
56
    {
57
        $fks = $this->tdbmSchemaAnalyzer->getIncomingForeignKeys('country');
58
        $this->assertCount(5, $fks);
59
        $tables = [$fks[0]->getLocalTableName(), $fks[1]->getLocalTableName(), $fks[2]->getLocalTableName(), $fks[3]->getLocalTableName(), $fks[4]->getLocalTableName()];
60
        $this->assertContains('users', $tables);
61
        $this->assertContains('all_nullable', $tables);
62
        $this->assertContains('boats', $tables);
63
        $this->assertContains('states', $tables);
64
    }
65
66
    public function testGetPivotTableLinkedToTable(): void
67
    {
68
        $pivotTables = $this->tdbmSchemaAnalyzer->getPivotTableLinkedToTable('rights');
69
        $this->assertCount(1, $pivotTables);
70
        $this->assertEquals('roles_rights', $pivotTables[0]);
71
72
        $pivotTables = $this->tdbmSchemaAnalyzer->getPivotTableLinkedToTable('animal');
73
        $this->assertCount(0, $pivotTables);
74
75
        $pivotTables = $this->tdbmSchemaAnalyzer->getPivotTableLinkedToTable('animal');
76
        $this->assertCount(0, $pivotTables);
77
    }
78
}
79