Skip to content

Commit

Permalink
Get tests passing in mysql, postgres and sqlite locally
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Jan 9, 2024
1 parent 404eb54 commit aaa1502
Show file tree
Hide file tree
Showing 4 changed files with 357 additions and 20 deletions.
6 changes: 5 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@
bootstrap="tests/bootstrap.php"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd"
>

<testsuites>
<testsuite name="migrations">
<directory>tests/TestCase</directory>
<exclude>tests/TestCase/TestSuite</exclude>
<exclude>tests/TestCase/Migration/ManagerTest.php</exclude>
</testsuite>
<testsuite name="migrator">
<directory>tests/TestCase/TestSuite</directory>
</testsuite>
<!-- Has to run last individually as these tests drop the database -->
<testsuite name="manager">
<file>tests/TestCase/Migration/ManagerTest.php</file>
</testsuite>
</testsuites>

<extensions>
Expand Down
32 changes: 13 additions & 19 deletions tests/TestCase/Migration/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,15 @@ protected function prepareEnvironment(array $paths = []): AdapterInterface
}
// Emulate the results of Util::parseDsn()
$connectionConfig = ConnectionManager::getConfig('test');
$adapter = $connectionConfig['scheme'] ?? null;
if ($adapter === 'postgres') {
$adapter = 'pgsql';
}
if ($adapter === 'sqlserver') {
$adapter = 'sqlsrv';
}
$adapterConfig = [
'adapter' => $connectionConfig['scheme'],
'adapter' => $adapter,
'user' => $connectionConfig['username'],
'pass' => $connectionConfig['password'],
'host' => $connectionConfig['host'],
Expand Down Expand Up @@ -301,7 +308,7 @@ public function testPrintStatusMethodWithNoMigrations()

// override the migrations directory to an empty one
$configArray = $this->getConfigArray();
$configArray['paths']['migrations'] = $this->getCorrectedPath(__DIR__ . '/_files/nomigrations');
$configArray['paths']['migrations'] = ROOT . '/config/Nomigrations';
$config = new Config($configArray);

$this->manager->setConfig($config);
Expand Down Expand Up @@ -2470,7 +2477,7 @@ public function testReversibleMigrationWithFKConflictOnTableDrop()
public function testBreakpointsTogglingOperateAsExpected()
{
if ($this->getDriverType() !== 'mysql') {
$this->markTestSkipped('Mysql tests disabled.');
$this->markTestSkipped('Test requires mysql');
}
$configArray = $this->getConfigArray();
$adapter = $this->manager->getEnvironment('production')->getAdapter();
Expand Down Expand Up @@ -2673,22 +2680,9 @@ public function testPostgresFullMigration()
$this->markTestSkipped('Test requires postgres');
}

$configArray = $this->getConfigArray();
// override the migrations directory to use the reversible migrations
$configArray['paths']['migrations'] = [
$this->getCorrectedPath(__DIR__ . '/_files/postgres'),
];
$configArray['environments']['production'] = PGSQL_DB_CONFIG;
$config = new Config($configArray);
$this->manager->setConfig($config);

$adapter = $this->manager->getEnvironment('production')->getAdapter();

// ensure the database is empty
$adapter->dropSchema('public');
$adapter->createSchema('public');
$adapter->disconnect();

$adapter = $this->prepareEnvironment([
'migrations' => ROOT . '/config/Postgres',
]);
// migrate to the latest version
$this->manager->migrate('production');

Expand Down
Empty file.
Loading

0 comments on commit aaa1502

Please sign in to comment.