diff --git a/src/Migration/BuiltinBackend.php b/src/Migration/BuiltinBackend.php index 041d69c4..470621bc 100644 --- a/src/Migration/BuiltinBackend.php +++ b/src/Migration/BuiltinBackend.php @@ -13,22 +13,13 @@ */ namespace Migrations\Migration; -use Cake\Command\Command; use Cake\Console\Arguments; use Cake\Console\ConsoleIo; use Cake\Console\TestSuite\StubConsoleInput; use Cake\Console\TestSuite\StubConsoleOutput; -use Cake\Datasource\ConnectionManager; use DateTime; use InvalidArgumentException; -use Migrations\Command\StatusCommand; -use Phinx\Config\Config; -use Phinx\Config\ConfigInterface; -use Phinx\Db\Adapter\WrapperInterface; -use Migrations\Migration\Manager; -use RuntimeException; use Symfony\Component\Console\Input\ArrayInput; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\NullOutput; use Symfony\Component\Console\Output\OutputInterface; @@ -108,7 +99,6 @@ public function __construct(array $default = []) * - `connection` The datasource connection to use * - `source` The folder where migrations are in * - `plugin` The plugin containing the migrations - * * @return array The migrations list and their statuses */ public function status(array $options = []): array diff --git a/src/Migration/Manager.php b/src/Migration/Manager.php index 07523b2e..9d39f9ec 100644 --- a/src/Migration/Manager.php +++ b/src/Migration/Manager.php @@ -22,7 +22,9 @@ use Phinx\Util\Util; use Psr\Container\ContainerInterface; use RuntimeException; -use Symfony\Component\Console\Input\ArgvInput; +use Symfony\Component\Console\Input\ArrayInput; +use Symfony\Component\Console\Input\InputDefinition; +use Symfony\Component\Console\Input\InputOption; class Manager { @@ -848,7 +850,12 @@ function ($phpFile) { $io->verbose("Constructing $class."); - $input = new ArgvInput(); + $config = $this->getConfig(); + $input = new ArrayInput([ + '--plugin' => $config['plugin'], + '--source' => $config['source'], + '--connection' => $config->getConnection(), + ]); $output = new OutputAdapter($io); // instantiate it @@ -957,7 +964,17 @@ public function getSeeds(): array /** @var \Phinx\Seed\SeedInterface[] $seeds */ $seeds = []; - $input = new ArgvInput(); + $config = $this->getConfig(); + $optionDef = new InputDefinition([ + new InputOption('plugin', mode: InputOption::VALUE_OPTIONAL, default: ''), + new InputOption('connection', mode: InputOption::VALUE_OPTIONAL, default: ''), + new InputOption('source', mode: InputOption::VALUE_OPTIONAL, default: ''), + ]); + $input = new ArrayInput([ + '--plugin' => $config['plugin'], + '--connection' => $config->getConnection(), + '--source' => $config['source'], + ], $optionDef); $output = new OutputAdapter($this->io); foreach ($phpFiles as $filePath) { diff --git a/src/Migration/ManagerFactory.php b/src/Migration/ManagerFactory.php index 7e30f477..efeabfeb 100644 --- a/src/Migration/ManagerFactory.php +++ b/src/Migration/ManagerFactory.php @@ -118,6 +118,8 @@ public function createConfig(): ConfigInterface ], 'migration_base_class' => 'Migrations\AbstractMigration', 'environment' => $adapterConfig, + 'plugin' => $plugin, + 'source' => (string)$this->getOption('source'), // TODO do we want to support the DI container in migrations? ]; diff --git a/src/Migrations.php b/src/Migrations.php index c0fcc5a7..1ed553b9 100644 --- a/src/Migrations.php +++ b/src/Migrations.php @@ -15,14 +15,10 @@ use Cake\Core\Configure; use Cake\Datasource\ConnectionManager; -use DateTime; use InvalidArgumentException; use Migrations\Migration\BuiltinBackend; use Migrations\Migration\PhinxBackend; -use Phinx\Config\Config; use Phinx\Config\ConfigInterface; -use Phinx\Db\Adapter\WrapperInterface; -use Phinx\Migration\Manager; use RuntimeException; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\InputInterface; @@ -32,8 +28,6 @@ /** * The Migrations class is responsible for handling migrations command * within an none-shell application. - * - * TODO(mark) This needs to be adapted to use the configure backend selection. */ class Migrations { diff --git a/tests/TestCase/MigrationsTest.php b/tests/TestCase/MigrationsTest.php index d08b8bb9..3fc57022 100644 --- a/tests/TestCase/MigrationsTest.php +++ b/tests/TestCase/MigrationsTest.php @@ -20,7 +20,6 @@ use Cake\TestSuite\TestCase; use Exception; use InvalidArgumentException; -use Migrations\CakeAdapter; use Migrations\Migrations; use Phinx\Config\FeatureFlags; use Phinx\Db\Adapter\WrapperInterface; @@ -127,7 +126,7 @@ public static function backendProvider(): array { return [ ['builtin'], - ['phinx'] + ['phinx'], ]; }