Issues (291)

tests/SchemaLockFileDumperTest.php (8 issues)

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());
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->schemaLockFileDumper = new SchemaLockFileDumper(self::getConnection(), /** @scrutinizer ignore-deprecated */ new ArrayCache(), Configuration::getDefaultLockFilePath());
Loading history...
42
    }
43
44
    public function testSchemaLock(): void
45
    {
46
        $schemaFromConnec = self::getConnection()->getSchemaManager()->createSchema();
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\DBAL\Schema\Abs...Manager::createSchema() has been deprecated: Use {@link introspectSchema()} instead. ( Ignorable by Annotation )

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

46
        $schemaFromConnec = /** @scrutinizer ignore-deprecated */ self::getConnection()->getSchemaManager()->createSchema();

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

46
        $schemaFromConnec = /** @scrutinizer ignore-deprecated */ self::getConnection()->getSchemaManager()->createSchema();

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...
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) {
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\DBAL\Schema\Schema::getTableNames() has been deprecated: Use {@see getTables()} and {@see Table::getName()} instead. ( Ignorable by Annotation )

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

50
        foreach (/** @scrutinizer ignore-deprecated */ $schemaFromConnec->getTableNames() as $tableName) {

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...
51
            $tableNames[] = str_replace(['tdbm_testcase', 'postgres', 'tdbm'], 'public', $tableName);
52
        }
53
54
        $cache = new ArrayCache();
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

54
        $cache = /** @scrutinizer ignore-deprecated */ new ArrayCache();
Loading history...
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();
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\DBAL\Schema\Schema::getTableNames() has been deprecated: Use {@see getTables()} and {@see Table::getName()} instead. ( Ignorable by Annotation )

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

60
        $tablesFromAnalyser = /** @scrutinizer ignore-deprecated */ $schemaFromAnalyser->getTableNames();

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...
61
        sort($tablesFromAnalyser);
62
        $tablesFromAnalyserCached = $schemaFromAnalyserCached->getTableNames();
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\DBAL\Schema\Schema::getTableNames() has been deprecated: Use {@see getTables()} and {@see Table::getName()} instead. ( Ignorable by Annotation )

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

62
        $tablesFromAnalyserCached = /** @scrutinizer ignore-deprecated */ $schemaFromAnalyserCached->getTableNames();

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...
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();
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

70
        $cache = /** @scrutinizer ignore-deprecated */ new ArrayCache();
Loading history...
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