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
|
|
|
|