|
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
|
|
|
use function sort; |
|
30
|
|
|
|
|
31
|
|
|
class SchemaLockFileDumperTest extends TDBMAbstractServiceTest |
|
32
|
|
|
{ |
|
33
|
|
|
/** |
|
34
|
|
|
* @var SchemaLockFileDumper |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $schemaLockFileDumper; |
|
37
|
|
|
|
|
38
|
|
|
protected function setUp(): void |
|
39
|
|
|
{ |
|
40
|
|
|
parent::setUp(); |
|
41
|
|
|
$this->schemaLockFileDumper = new SchemaLockFileDumper(self::getConnection(), new ArrayCache(), Configuration::getDefaultLockFilePath()); |
|
|
|
|
|
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function testSchemaLock(): void |
|
45
|
|
|
{ |
|
46
|
|
|
$schemaFromConnec = self::getConnection()->createSchemaManager()->createSchema(); |
|
|
|
|
|
|
47
|
|
|
$tableNames = []; |
|
48
|
|
|
//lock file doesn't save the database name so we have to replace it manually. |
|
49
|
|
|
ImmutableCaster::castSchemaToImmutable($schemaFromConnec); |
|
50
|
|
|
foreach ($schemaFromConnec->getTableNames() as $tableName) { |
|
|
|
|
|
|
51
|
|
|
$tableNames[] = str_replace(['tdbm_testcase', 'postgres', 'tdbm'], 'public', $tableName); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
$cache = new ArrayCache(); |
|
|
|
|
|
|
55
|
|
|
$schemaLockFileDumper = new SchemaLockFileDumper(self::getConnection(), $cache, Configuration::getDefaultLockFilePath()); |
|
56
|
|
|
|
|
57
|
|
|
$schemaFromAnalyser = $schemaLockFileDumper->getSchema(true); |
|
58
|
|
|
$schemaFromAnalyserCached = $schemaLockFileDumper->getSchema(); |
|
59
|
|
|
sort($tableNames); |
|
60
|
|
|
$tablesFromAnalyser = $schemaFromAnalyser->getTableNames(); |
|
|
|
|
|
|
61
|
|
|
sort($tablesFromAnalyser); |
|
62
|
|
|
$tablesFromAnalyserCached = $schemaFromAnalyserCached->getTableNames(); |
|
|
|
|
|
|
63
|
|
|
sort($tablesFromAnalyserCached); |
|
64
|
|
|
$this->assertEquals($tableNames, $tablesFromAnalyser); |
|
65
|
|
|
$this->assertEquals($tablesFromAnalyser, $tablesFromAnalyserCached); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function testGetSchema(): void |
|
69
|
|
|
{ |
|
70
|
|
|
$cache = new ArrayCache(); |
|
|
|
|
|
|
71
|
|
|
$schemaLockFileDumper1 = new SchemaLockFileDumper(self::getConnection(), $cache, Configuration::getDefaultLockFilePath()); |
|
72
|
|
|
$schemaLockFileDumper2 = new SchemaLockFileDumper(self::getConnection(), $cache, Configuration::getDefaultLockFilePath()); |
|
73
|
|
|
|
|
74
|
|
|
// Why don't we go in all lines of code???? |
|
75
|
|
|
$schema1 = $schemaLockFileDumper1->getSchema(); |
|
76
|
|
|
// One more time to go through cache! |
|
77
|
|
|
$schema2 = $schemaLockFileDumper2->getSchema(); |
|
78
|
|
|
$this->assertTrue($schema1 === $schema2); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|