Skip to content

Commit

Permalink
Merge pull request #684 from cakephp/manager-integration
Browse files Browse the repository at this point in the history
Get manager tests passing with new backend
  • Loading branch information
markstory authored Jan 29, 2024
2 parents 1a3682e + 9a8a7ca commit f427320
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 37 deletions.
7 changes: 3 additions & 4 deletions src/Migration/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Phinx\Config\ConfigInterface;
use Phinx\Config\NamespaceAwareInterface;
use Phinx\Migration\AbstractMigration;
use Phinx\Migration\Manager\Environment;
use Phinx\Migration\MigrationInterface;
use Phinx\Seed\AbstractSeed;
use Phinx\Seed\SeedInterface;
Expand Down Expand Up @@ -46,7 +45,7 @@ class Manager
protected OutputInterface $output;

/**
* @var \Phinx\Migration\Manager\Environment[]
* @var \Migrations\Migration\Environment[]
*/
protected array $environments = [];

Expand Down Expand Up @@ -718,7 +717,7 @@ public function seed(string $environment, ?string $seed = null): void
/**
* Sets the environments.
*
* @param \Phinx\Migration\Manager\Environment[] $environments Environments
* @param \Migrations\Migration\Environment[] $environments Environments
* @return $this
*/
public function setEnvironments(array $environments = [])
Expand All @@ -733,7 +732,7 @@ public function setEnvironments(array $environments = [])
*
* @param string $name Environment Name
* @throws \InvalidArgumentException
* @return \Phinx\Migration\Manager\Environment
* @return \Migrations\Migration\Environment
*/
public function getEnvironment(string $name): Environment
{
Expand Down
61 changes: 28 additions & 33 deletions tests/TestCase/Migration/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
use Cake\Datasource\ConnectionManager;
use DateTime;
use InvalidArgumentException;
use Migrations\Db\Adapter\AdapterInterface;
use Migrations\Migration\Environment;
use Migrations\Migration\Manager;
use Phinx\Config\Config;
use Phinx\Console\Command\AbstractCommand;
use Phinx\Db\Adapter\AdapterInterface;
use PHPUnit\Framework\TestCase;
use RuntimeException;
use Symfony\Component\Console\Input\ArrayInput;
Expand Down Expand Up @@ -121,7 +122,7 @@ protected function getConfigWithPlugin($paths = [])
* Prepares an environment for cross DBMS functional tests.
*
* @param array $paths The paths config to override.
* @return \Phinx\Db\Adapter\AdapterInterface
* @return \Migrations\Db\Adapter\AdapterInterface
*/
protected function prepareEnvironment(array $paths = []): AdapterInterface
{
Expand All @@ -134,12 +135,6 @@ 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' => $adapter,
'user' => $connectionConfig['username'],
Expand All @@ -154,7 +149,7 @@ protected function prepareEnvironment(array $paths = []): AdapterInterface
$adapter = $this->manager->getEnvironment('production')->getAdapter();

// ensure the database is empty
if ($adapterConfig['adapter'] === 'pgsql') {
if ($adapterConfig['adapter'] === 'postgres') {
$adapter->dropSchema('public');
$adapter->createSchema('public');
} elseif ($adapterConfig['name'] !== ':memory:') {
Expand Down Expand Up @@ -185,7 +180,7 @@ public function testEnvironmentInheritsDataDomainOptions()
public function testPrintStatusMethod()
{
// stub environment
$envStub = $this->getMockBuilder('\Phinx\Migration\Manager\Environment')
$envStub = $this->getMockBuilder(Environment::class)
->setConstructorArgs(['mockenv', []])
->getMock();
$envStub->expects($this->once())
Expand Down Expand Up @@ -232,7 +227,7 @@ public function testPrintStatusMethod()
public function testPrintStatusMethodJsonFormat()
{
// stub environment
$envStub = $this->getMockBuilder('\Phinx\Migration\Manager\Environment')
$envStub = $this->getMockBuilder(Environment::class)
->setConstructorArgs(['mockenv', []])
->getMock();
$envStub->expects($this->once())
Expand Down Expand Up @@ -278,7 +273,7 @@ public function testPrintStatusMethodJsonFormat()
public function testPrintStatusMethodWithBreakpointSet()
{
// stub environment
$envStub = $this->getMockBuilder('\Phinx\Migration\Manager\Environment')
$envStub = $this->getMockBuilder(Environment::class)
->setConstructorArgs(['mockenv', []])
->getMock();
$envStub->expects($this->once())
Expand Down Expand Up @@ -325,7 +320,7 @@ public function testPrintStatusMethodWithBreakpointSet()
public function testPrintStatusMethodWithNoMigrations()
{
// stub environment
$envStub = $this->getMockBuilder('\Phinx\Migration\Manager\Environment')
$envStub = $this->getMockBuilder(Environment::class)
->setConstructorArgs(['mockenv', []])
->getMock();

Expand All @@ -344,7 +339,7 @@ public function testPrintStatusMethodWithNoMigrations()
public function testPrintStatusMethodWithMissingMigrations()
{
// stub environment
$envStub = $this->getMockBuilder('\Phinx\Migration\Manager\Environment')
$envStub = $this->getMockBuilder(Environment::class)
->setConstructorArgs(['mockenv', []])
->getMock();
$envStub->expects($this->once())
Expand Down Expand Up @@ -403,7 +398,7 @@ public function testPrintStatusMethodWithMissingMigrations()
public function testPrintStatusMethodWithMissingLastMigration()
{
// stub environment
$envStub = $this->getMockBuilder('\Phinx\Migration\Manager\Environment')
$envStub = $this->getMockBuilder(Environment::class)
->setConstructorArgs(['mockenv', []])
->getMock();
$envStub->expects($this->once())
Expand Down Expand Up @@ -464,7 +459,7 @@ public function testPrintStatusMethodWithMissingLastMigration()
public function testPrintStatusMethodWithMissingMigrationsAndBreakpointSet()
{
// stub environment
$envStub = $this->getMockBuilder('\Phinx\Migration\Manager\Environment')
$envStub = $this->getMockBuilder(Environment::class)
->setConstructorArgs(['mockenv', []])
->getMock();
$envStub->expects($this->once())
Expand Down Expand Up @@ -523,7 +518,7 @@ public function testPrintStatusMethodWithMissingMigrationsAndBreakpointSet()
public function testPrintStatusMethodWithDownMigrations()
{
// stub environment
$envStub = $this->getMockBuilder('\Phinx\Migration\Manager\Environment')
$envStub = $this->getMockBuilder(Environment::class)
->setConstructorArgs(['mockenv', []])
->getMock();
$envStub->expects($this->once())
Expand Down Expand Up @@ -558,7 +553,7 @@ public function testPrintStatusMethodWithDownMigrations()
public function testPrintStatusMethodWithMissingAndDownMigrations()
{
// stub environment
$envStub = $this->getMockBuilder('\Phinx\Migration\Manager\Environment')
$envStub = $this->getMockBuilder(Environment::class)
->setConstructorArgs(['mockenv', []])
->getMock();
$envStub->expects($this->once())
Expand Down Expand Up @@ -656,7 +651,7 @@ public function testGetMigrationsWithInvalidMigrationClassName()
public function testGettingAValidEnvironment()
{
$this->assertInstanceOf(
'Phinx\Migration\Manager\Environment',
Environment::class,
$this->manager->getEnvironment('production')
);
}
Expand All @@ -674,7 +669,7 @@ public function testGettingAValidEnvironment()
public function testMigrationsByDate(array $availableMigrations, $dateString, $expectedMigration, $message)
{
// stub environment
$envStub = $this->getMockBuilder('\Phinx\Migration\Manager\Environment')
$envStub = $this->getMockBuilder(Environment::class)
->setConstructorArgs(['mockenv', []])
->getMock();
if (is_null($expectedMigration)) {
Expand Down Expand Up @@ -705,7 +700,7 @@ public function testMigrationsByDate(array $availableMigrations, $dateString, $e
public function testRollbackToVersion($availableRollbacks, $version, $expectedOutput)
{
// stub environment
$envStub = $this->getMockBuilder('\Phinx\Migration\Manager\Environment')
$envStub = $this->getMockBuilder(Environment::class)
->setConstructorArgs(['mockenv', []])
->getMock();
$envStub->expects($this->any())
Expand Down Expand Up @@ -738,7 +733,7 @@ public function testRollbackToVersion($availableRollbacks, $version, $expectedOu
public function testRollbackToDate($availableRollbacks, $version, $expectedOutput)
{
// stub environment
$envStub = $this->getMockBuilder('\Phinx\Migration\Manager\Environment')
$envStub = $this->getMockBuilder(Environment::class)
->setConstructorArgs(['mockenv', []])
->getMock();
$envStub->expects($this->any())
Expand Down Expand Up @@ -771,7 +766,7 @@ public function testRollbackToDate($availableRollbacks, $version, $expectedOutpu
public function testRollbackToVersionByExecutionTime($availableRollbacks, $version, $expectedOutput)
{
// stub environment
$envStub = $this->getMockBuilder('\Phinx\Migration\Manager\Environment')
$envStub = $this->getMockBuilder(Environment::class)
->setConstructorArgs(['mockenv', []])
->getMock();
$envStub->expects($this->any())
Expand Down Expand Up @@ -814,7 +809,7 @@ public function testRollbackToVersionByExecutionTime($availableRollbacks, $versi
public function testRollbackToVersionByName($availableRollbacks, $version, $expectedOutput)
{
// stub environment
$envStub = $this->getMockBuilder('\Phinx\Migration\Manager\Environment')
$envStub = $this->getMockBuilder(Environment::class)
->setConstructorArgs(['mockenv', []])
->getMock();
$envStub->expects($this->any())
Expand Down Expand Up @@ -857,7 +852,7 @@ public function testRollbackToVersionByName($availableRollbacks, $version, $expe
public function testRollbackToDateByExecutionTime($availableRollbacks, $date, $expectedOutput)
{
// stub environment
$envStub = $this->getMockBuilder('\Phinx\Migration\Manager\Environment')
$envStub = $this->getMockBuilder(Environment::class)
->setConstructorArgs(['mockenv', []])
->getMock();
$envStub->expects($this->any())
Expand Down Expand Up @@ -894,7 +889,7 @@ public function testRollbackToDateByExecutionTime($availableRollbacks, $date, $e
public function testRollbackToVersionWithSingleMigrationDoesNotFail()
{
// stub environment
$envStub = $this->getMockBuilder('\Phinx\Migration\Manager\Environment')
$envStub = $this->getMockBuilder(Environment::class)
->setConstructorArgs(['mockenv', []])
->getMock();
$envStub->expects($this->any())
Expand All @@ -919,7 +914,7 @@ public function testRollbackToVersionWithSingleMigrationDoesNotFail()
public function testRollbackToVersionWithTwoMigrations()
{
// stub environment
$envStub = $this->getMockBuilder('\Phinx\Migration\Manager\Environment')
$envStub = $this->getMockBuilder(Environment::class)
->setConstructorArgs(['mockenv', []])
->getMock();
$envStub->expects($this->any())
Expand Down Expand Up @@ -958,7 +953,7 @@ public function testRollbackToVersionWithTwoMigrations()
public function testRollbackLast($availableRolbacks, $versionOrder, $expectedOutput)
{
// stub environment
$envStub = $this->getMockBuilder('\Phinx\Migration\Manager\Environment')
$envStub = $this->getMockBuilder(Environment::class)
->setConstructorArgs(['mockenv', []])
->getMock();
$envStub->expects($this->any())
Expand Down Expand Up @@ -2253,7 +2248,7 @@ public static function rollbackLastDataProvider()
public function testExecuteSeedWorksAsExpected()
{
// stub environment
$envStub = $this->getMockBuilder('\Phinx\Migration\Manager\Environment')
$envStub = $this->getMockBuilder(Environment::class)
->setConstructorArgs(['mockenv', []])
->getMock();
$this->manager->setEnvironments(['mockenv' => $envStub]);
Expand All @@ -2268,7 +2263,7 @@ public function testExecuteSeedWorksAsExpected()
public function testExecuteASingleSeedWorksAsExpected()
{
// stub environment
$envStub = $this->getMockBuilder('\Phinx\Migration\Manager\Environment')
$envStub = $this->getMockBuilder(Environment::class)
->setConstructorArgs(['mockenv', []])
->getMock();
$this->manager->setEnvironments(['mockenv' => $envStub]);
Expand All @@ -2281,7 +2276,7 @@ public function testExecuteASingleSeedWorksAsExpected()
public function testExecuteANonExistentSeedWorksAsExpected()
{
// stub environment
$envStub = $this->getMockBuilder('\Phinx\Migration\Manager\Environment')
$envStub = $this->getMockBuilder(Environment::class)
->setConstructorArgs(['mockenv', []])
->getMock();
$this->manager->setEnvironments(['mockenv' => $envStub]);
Expand All @@ -2303,7 +2298,7 @@ public function testOrderSeeds()
public function testSeedWillNotBeExecuted()
{
// stub environment
$envStub = $this->getMockBuilder('\Phinx\Migration\Manager\Environment')
$envStub = $this->getMockBuilder(Environment::class)
->setConstructorArgs(['mockenv', []])
->getMock();
$this->manager->setEnvironments(['mockenv' => $envStub]);
Expand Down Expand Up @@ -2775,7 +2770,7 @@ public function testMigrationWithDropColumnAndForeignKeyAndIndex()
public function testInvalidVersionBreakpoint()
{
// stub environment
$envStub = $this->getMockBuilder('\Phinx\Migration\Manager\Environment')
$envStub = $this->getMockBuilder(Environment::class)
->setConstructorArgs(['mockenv', []])
->getMock();
$envStub->expects($this->once())
Expand Down

0 comments on commit f427320

Please sign in to comment.