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