Skip to content

Commit 61db159

Browse files
committed
Actually using the LockFileSchemaManager
1 parent 7be39b3 commit 61db159

8 files changed

+20
-38
lines changed

phpunit.mariadb.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@
2525
<var name="db_port" value="3306"/>
2626
<var name="db_driver" value="pdo_mysql"/>
2727
</php>
28-
28+
2929
<filter>
3030
<whitelist processUncoveredFilesFromWhitelist="true">
3131
<directory suffix=".php">src/</directory>
3232
<exclude>
3333
<directory suffix=".php">src/Test</directory>
34+
<file>src/Schema/LockFileSchemaManager.php</file>
3435
</exclude>
3536
</whitelist>
3637
</filter>

phpunit.mysql8.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@
2525
<var name="db_port" value="3306"/>
2626
<var name="db_driver" value="pdo_mysql"/>
2727
</php>
28-
28+
2929
<filter>
3030
<whitelist processUncoveredFilesFromWhitelist="true">
3131
<directory suffix=".php">src/</directory>
3232
<exclude>
3333
<directory suffix=".php">src/Test</directory>
34+
<file>src/Schema/LockFileSchemaManager.php</file>
3435
</exclude>
3536
</whitelist>
3637
</filter>

phpunit.oracle.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@
2626
<var name="db_port" value="1521"/>
2727
<var name="db_driver" value="oci8"/>
2828
</php>
29-
29+
3030
<filter>
3131
<whitelist processUncoveredFilesFromWhitelist="true">
3232
<directory suffix=".php">src/</directory>
3333
<exclude>
3434
<directory suffix=".php">src/Test</directory>
35+
<file>src/Schema/LockFileSchemaManager.php</file>
3536
</exclude>
3637
</whitelist>
3738
</filter>

phpunit.postgres.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@
2525
<var name="db_port" value="5432"/>
2626
<var name="db_driver" value="pdo_pgsql"/>
2727
</php>
28-
28+
2929
<filter>
3030
<whitelist processUncoveredFilesFromWhitelist="true">
3131
<directory suffix=".php">src/</directory>
3232
<exclude>
3333
<directory suffix=".php">src/Test</directory>
34+
<file>src/Schema/LockFileSchemaManager.php</file>
3435
</exclude>
3536
</whitelist>
3637
</filter>

phpunit.xml.dist

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

3-
<phpunit backupGlobals="false"
3+
<phpunit
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.5/phpunit.xsd"
6+
backupGlobals="false"
47
backupStaticAttributes="false"
58
colors="true"
69
convertErrorsToExceptions="true"
@@ -25,12 +28,13 @@
2528
<var name="db_port" value="3306"/>
2629
<var name="db_driver" value="pdo_mysql"/>
2730
</php>
28-
31+
2932
<filter>
3033
<whitelist processUncoveredFilesFromWhitelist="true">
3134
<directory suffix=".php">src/</directory>
3235
<exclude>
3336
<directory suffix=".php">src/Test</directory>
37+
<file>src/Schema/LockFileSchemaManager.php</file>
3438
</exclude>
3539
</whitelist>
3640
</filter>

src/Configuration.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Doctrine\Common\Cache\VoidCache;
99
use Doctrine\DBAL\Connection;
1010
use Mouf\Database\SchemaAnalyzer\SchemaAnalyzer;
11+
use TheCodingMachine\TDBM\Schema\LockFileSchemaManager;
1112
use TheCodingMachine\TDBM\Utils\Annotation\AnnotationParser;
1213
use TheCodingMachine\TDBM\Utils\Annotation\Autoincrement;
1314
use TheCodingMachine\TDBM\Utils\Annotation\UUID;
@@ -118,7 +119,9 @@ public function __construct(
118119
} else {
119120
$this->cache = new VoidCache();
120121
}
121-
$lockFileSchemaManager = $this->connection->getSchemaManager();
122+
$this->lockFilePath = $lockFilePath;
123+
$schemaLockFileDumper = new SchemaLockFileDumper($this->connection, $this->cache, $this->getLockFilePath());
124+
$lockFileSchemaManager = new LockFileSchemaManager($this->connection->getSchemaManager(), $schemaLockFileDumper);
122125
if ($schemaAnalyzer !== null) {
123126
$this->schemaAnalyzer = $schemaAnalyzer;
124127
} else {
@@ -130,7 +133,6 @@ public function __construct(
130133
$this->annotationParser = $annotationParser ?: AnnotationParser::buildWithDefaultAnnotations([]);
131134
$this->codeGeneratorListener = new CodeGeneratorEventDispatcher($codeGeneratorListeners);
132135
$this->namingStrategy = $namingStrategy ?: new DefaultNamingStrategy($this->annotationParser, $lockFileSchemaManager);
133-
$this->lockFilePath = $lockFilePath;
134136
}
135137

136138
/**

tests/Commands/AlteredConfigurationTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
use Doctrine\Common\Cache\Cache;
77
use Doctrine\DBAL\Connection;
8+
use Doctrine\DBAL\Schema\AbstractSchemaManager;
89
use Mouf\Database\SchemaAnalyzer\SchemaAnalyzer;
910
use PHPUnit\Framework\TestCase;
1011
use TheCodingMachine\TDBM\Configuration;
@@ -17,6 +18,7 @@ class AlteredConfigurationTest extends TestCase
1718
public function testAlteredConfiguration(): void
1819
{
1920
$connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock();
21+
$connection->method('getSchemaManager')->willReturn($this->createMock(AbstractSchemaManager::class));
2022
$namingStrategy = $this->getMockBuilder(NamingStrategyInterface::class)->disableOriginalConstructor()->getMock();
2123
$cache = $this->getMockBuilder(Cache::class)->disableOriginalConstructor()->getMock();
2224
$logger = $this->getMockBuilder(LoggerInterface::class)->disableOriginalConstructor()->getMock();

tests/TDBMSchemaAnalyzerTest.php

-30
Original file line numberDiff line numberDiff line change
@@ -42,30 +42,18 @@ protected function setUp(): void
4242

4343
public function testGetIncomingForeignKeys(): void
4444
{
45-
/*$schemaAnalyzer = new SchemaAnalyzer(self::getConnection()->getSchemaManager(), new ArrayCache(), 'prefix_');
46-
$cache = new ArrayCache();
47-
$tdbmSchemaAnalyzer = new TDBMSchemaAnalyzer(self::getConnection(), $cache, $schemaAnalyzer, Configuration::getDefaultLockFilePath());*/
48-
4945
$fks = $this->tdbmSchemaAnalyzer->getIncomingForeignKeys('users');
5046
$this->assertCount(1, $fks);
5147
}
5248

5349
public function testGetIncomingForeignKeys2(): void
5450
{
55-
/*$schemaAnalyzer = new SchemaAnalyzer(self::getConnection()->getSchemaManager(), new ArrayCache(), 'prefix_');
56-
$cache = new ArrayCache();
57-
$tdbmSchemaAnalyzer = new TDBMSchemaAnalyzer(self::getConnection(), $cache, $schemaAnalyzer, Configuration::getDefaultLockFilePath());*/
58-
5951
$fks = $this->tdbmSchemaAnalyzer->getIncomingForeignKeys('contact');
6052
$this->assertCount(1, $fks);
6153
}
6254

6355
public function testGetIncomingForeignKeys3(): void
6456
{
65-
/*$schemaAnalyzer = new SchemaAnalyzer(self::getConnection()->getSchemaManager(), new ArrayCache(), 'prefix_');
66-
$cache = new ArrayCache();
67-
$tdbmSchemaAnalyzer = new TDBMSchemaAnalyzer(self::getConnection(), $cache, $schemaAnalyzer, Configuration::getDefaultLockFilePath());*/
68-
6957
$fks = $this->tdbmSchemaAnalyzer->getIncomingForeignKeys('country');
7058
$this->assertCount(5, $fks);
7159
$tables = [$fks[0]->getLocalTableName(), $fks[1]->getLocalTableName(), $fks[2]->getLocalTableName(), $fks[3]->getLocalTableName(), $fks[4]->getLocalTableName()];
@@ -77,10 +65,6 @@ public function testGetIncomingForeignKeys3(): void
7765

7866
public function testGetPivotTableLinkedToTable(): void
7967
{
80-
/*$schemaAnalyzer = new SchemaAnalyzer(self::getConnection()->getSchemaManager(), new ArrayCache(), 'prefix_');
81-
$cache = new ArrayCache();
82-
$tdbmSchemaAnalyzer = new TDBMSchemaAnalyzer(self::getConnection(), $cache, $schemaAnalyzer, Configuration::getDefaultLockFilePath());*/
83-
8468
$pivotTables = $this->tdbmSchemaAnalyzer->getPivotTableLinkedToTable('rights');
8569
$this->assertCount(1, $pivotTables);
8670
$this->assertEquals('roles_rights', $pivotTables[0]);
@@ -91,18 +75,4 @@ public function testGetPivotTableLinkedToTable(): void
9175
$pivotTables = $this->tdbmSchemaAnalyzer->getPivotTableLinkedToTable('animal');
9276
$this->assertCount(0, $pivotTables);
9377
}
94-
95-
/*public function testGetCompulsoryColumnsWithNoInheritance() {
96-
$table = $this->tdbmSchemaAnalyzer->getSchema()->getTable('country');
97-
$compulsoryColumns = $this->tdbmSchemaAnalyzer->getCompulsoryProperties($table);
98-
$this->assertCount(1, $compulsoryColumns);
99-
$this->assertArrayHasKey("label", $compulsoryColumns);
100-
}
101-
102-
public function testGetCompulsoryColumnsWithInheritance() {
103-
$table = $this->tdbmSchemaAnalyzer->getSchema()->getTable('users');
104-
$compulsoryColumns = $this->tdbmSchemaAnalyzer->getCompulsoryProperties($table);
105-
$this->assertCount(5, $compulsoryColumns);
106-
$this->assertEquals(['name', 'created_at', 'email', 'country_id', 'login'], array_keys($compulsoryColumns));
107-
}*/
10878
}

0 commit comments

Comments
 (0)