Completed
Push — master ( 76242e...b0246c )
by David
19s queued 16s
created

SchemaLockFileDumperTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 21
c 1
b 0
f 0
dl 0
loc 43
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetSchema() 0 11 1
A setUp() 0 4 1
A testSchemaLock() 0 17 2
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