testGetIncomingForeignKeys3()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 7
c 3
b 0
f 0
dl 0
loc 9
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 Copyright (C) 2006-2014 David Négrier - THE CODING MACHINE
7
8
This program is free software; you can redistribute it and/or modify
9
it under the terms of the GNU General Public License as published by
10
the Free Software Foundation; either version 2 of the License, or
11
(at your option) any later version.
12
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
GNU General Public License for more details.
17
18
You should have received a copy of the GNU General Public License
19
along with this program; if not, write to the Free Software
20
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21
*/
22
23
namespace TheCodingMachine\TDBM;
24
25
use Doctrine\Common\Cache\ArrayCache;
26
use Mouf\Database\SchemaAnalyzer\SchemaAnalyzer;
27
use TheCodingMachine\TDBM\Utils\ImmutableCaster;
28
29
class TDBMSchemaAnalyzerTest extends TDBMAbstractServiceTest
30
{
31
    /**
32
     * @var TDBMSchemaAnalyzer
33
     */
34
    protected $tdbmSchemaAnalyzer;
35
36
    protected function setUp(): void
37
    {
38
        parent::setUp();
39
        $schemaAnalyzer = new SchemaAnalyzer(self::getConnection()->getSchemaManager(), new ArrayCache(), 'prefix_');
0 ignored issues
show
Deprecated Code introduced by
The class Doctrine\Common\Cache\ArrayCache has been deprecated: Deprecated without replacement in doctrine/cache 1.11. This class will be dropped in 2.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

39
        $schemaAnalyzer = new SchemaAnalyzer(self::getConnection()->getSchemaManager(), /** @scrutinizer ignore-deprecated */ new ArrayCache(), 'prefix_');
Loading history...
Deprecated Code introduced by
The function Doctrine\DBAL\Connection::getSchemaManager() has been deprecated: Use {@see createSchemaManager()} instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

39
        $schemaAnalyzer = new SchemaAnalyzer(/** @scrutinizer ignore-deprecated */ self::getConnection()->getSchemaManager(), new ArrayCache(), 'prefix_');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
40
        $schemaLockFileDumper = new SchemaLockFileDumper(self::getConnection(), new ArrayCache(), Configuration::getDefaultLockFilePath());
0 ignored issues
show
Deprecated Code introduced by
The class Doctrine\Common\Cache\ArrayCache has been deprecated: Deprecated without replacement in doctrine/cache 1.11. This class will be dropped in 2.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

40
        $schemaLockFileDumper = new SchemaLockFileDumper(self::getConnection(), /** @scrutinizer ignore-deprecated */ new ArrayCache(), Configuration::getDefaultLockFilePath());
Loading history...
41
        $this->tdbmSchemaAnalyzer = new TDBMSchemaAnalyzer(self::getConnection(), new ArrayCache(), $schemaAnalyzer, $schemaLockFileDumper);
0 ignored issues
show
Deprecated Code introduced by
The class Doctrine\Common\Cache\ArrayCache has been deprecated: Deprecated without replacement in doctrine/cache 1.11. This class will be dropped in 2.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

41
        $this->tdbmSchemaAnalyzer = new TDBMSchemaAnalyzer(self::getConnection(), /** @scrutinizer ignore-deprecated */ new ArrayCache(), $schemaAnalyzer, $schemaLockFileDumper);
Loading history...
42
    }
43
44
    public function testGetIncomingForeignKeys(): void
45
    {
46
        $fks = $this->tdbmSchemaAnalyzer->getIncomingForeignKeys('users');
47
        $this->assertCount(1, $fks);
48
    }
49
50
    public function testGetIncomingForeignKeys2(): void
51
    {
52
        $fks = $this->tdbmSchemaAnalyzer->getIncomingForeignKeys('contact');
53
        $this->assertCount(1, $fks);
54
    }
55
56
    public function testGetIncomingForeignKeys3(): void
57
    {
58
        $fks = $this->tdbmSchemaAnalyzer->getIncomingForeignKeys('country');
59
        $this->assertCount(5, $fks);
60
        $tables = [$fks[0]->getLocalTableName(), $fks[1]->getLocalTableName(), $fks[2]->getLocalTableName(), $fks[3]->getLocalTableName(), $fks[4]->getLocalTableName()];
61
        $this->assertContains('users', $tables);
62
        $this->assertContains('all_nullable', $tables);
63
        $this->assertContains('boats', $tables);
64
        $this->assertContains('states', $tables);
65
    }
66
67
    public function testGetPivotTableLinkedToTable(): void
68
    {
69
        $pivotTables = $this->tdbmSchemaAnalyzer->getPivotTableLinkedToTable('rights');
70
        $this->assertCount(1, $pivotTables);
71
        $this->assertEquals('roles_rights', $pivotTables[0]);
72
73
        $pivotTables = $this->tdbmSchemaAnalyzer->getPivotTableLinkedToTable('animal');
74
        $this->assertCount(0, $pivotTables);
75
76
        $pivotTables = $this->tdbmSchemaAnalyzer->getPivotTableLinkedToTable('animal');
77
        $this->assertCount(0, $pivotTables);
78
    }
79
}
80