From 518e2a55f8475c4a1dc05e95e5d696c4aface837 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Arne=20J=C3=B8rgensen?= <arne@arnested.dk>
Date: Tue, 5 Feb 2019 22:39:36 +0100
Subject: [PATCH] Issue #3024399: The "--limit" option does not accept a value
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Default values (including self::REQ for required value for options) much
be declared as default values in the function signature for
Consolidation\AnnotatedCommand to parse them right.

We also need to add an explicit empty options array when the commands
are called in the test cases.

Signed-off-by: Arne Jørgensen <arne@arnested.dk>
---
 src/Commands/MigrateToolsCommands.php | 64 +++++++++++++--------------
 tests/src/Kernel/DrushTest.php        | 10 ++---
 2 files changed, 35 insertions(+), 39 deletions(-)

diff --git a/src/Commands/MigrateToolsCommands.php b/src/Commands/MigrateToolsCommands.php
index dbae1fb..f9b951a 100644
--- a/src/Commands/MigrateToolsCommands.php
+++ b/src/Commands/MigrateToolsCommands.php
@@ -121,12 +121,11 @@ class MigrateToolsCommands extends DrushCommands {
    * @return \Consolidation\OutputFormatters\StructuredData\RowsOfFields
    *   Migrations status formatted as table.
    */
-  public function status($migration_names = '', array $options = []) {
-    $options += [
-      'group' => NULL,
-      'tag' => NULL,
-      'names-only' => NULL,
-    ];
+  public function status($migration_names = '', array $options = [
+    'group' => self::REQ,
+    'tag' => self::REQ,
+    'names-only' => FALSE,
+  ]) {
     $names_only = $options['names-only'];
 
     $migrations = $this->migrationsList($migration_names, $options);
@@ -272,19 +271,18 @@ class MigrateToolsCommands extends DrushCommands {
    * @throws \Exception
    *   If there are not enough parameters to the command.
    */
-  public function import($migration_names = '', array $options = []) {
-    $options += [
-      'all' => NULL,
-      'group' => NULL,
-      'tag' => NULL,
-      'limit' => NULL,
-      'feedback' => NULL,
-      'idlist' => NULL,
-      'idlist-delimiter' => ':',
-      'update' => NULL,
-      'force' => NULL,
-      'execute-dependencies' => NULL,
-    ];
+  public function import($migration_names = '', array $options = [
+    'all' => FALSE,
+    'group' => self::REQ,
+    'tag' => self::REQ,
+    'limit' => self::REQ,
+    'feedback' => self::REQ,
+    'idlist' => self::REQ,
+    'idlist-delimiter' => ':',
+    'update' => FALSE,
+    'force' => FALSE,
+    'execute-dependencies' => FALSE,
+  ]) {
     $group_names = $options['group'];
     $tag_names = $options['tag'];
     $all = $options['all'];
@@ -362,15 +360,14 @@ class MigrateToolsCommands extends DrushCommands {
    * @throws \Exception
    *   If there are not enough parameters to the command.
    */
-  public function rollback($migration_names = '', array $options = []) {
-    $options += [
-      'all' => NULL,
-      'group' => NULL,
-      'tag' => NULL,
-      'feedback' => NULL,
-      'idlist' => NULL,
-      'idlist-delimiter' => ':',
-    ];
+  public function rollback($migration_names = '', array $options = [
+    'all' => FALSE,
+    'group' => self::REQ,
+    'tag' => self::REQ,
+    'feedback' => self::REQ,
+    'idlist' => self::REQ,
+    'idlist-delimiter' => ':',
+  ]) {
     $group_names = $options['group'];
     $tag_names = $options['tag'];
     $all = $options['all'];
@@ -528,12 +525,11 @@ class MigrateToolsCommands extends DrushCommands {
    * @return \Consolidation\OutputFormatters\StructuredData\RowsOfFields
    *   Source fields of the given migration formatted as a table.
    */
-  public function messages($migration_id, array $options = []) {
-    $options += [
-      'csv' => NULL,
-      'idlist' => NULL,
-      'idlist-delimiter' => ':',
-    ];
+  public function messages($migration_id, array $options = [
+    'csv' => FALSE,
+    'idlist' => self::REQ,
+    'idlist-delimiter' => ':',
+  ]) {
     /** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
     $migration = $this->migrationPluginManager->createInstance(
       $migration_id
diff --git a/tests/src/Kernel/DrushTest.php b/tests/src/Kernel/DrushTest.php
index 6929c96..b701988 100644
--- a/tests/src/Kernel/DrushTest.php
+++ b/tests/src/Kernel/DrushTest.php
@@ -89,7 +89,7 @@ class DrushTest extends MigrateTestBase {
   public function testStatus() {
     $this->executeMigration('fruit_terms');
     /** @var \Consolidation\OutputFormatters\StructuredData\RowsOfFields $result */
-    $result = $this->commands->status('fruit_terms');
+    $result = $this->commands->status('fruit_terms', []);
     $rows = $result->getArrayCopy();
     $this->assertSame(1, count($rows));
     $row = reset($rows);
@@ -110,7 +110,7 @@ class DrushTest extends MigrateTestBase {
     $id_map = $migration->getIdMap();
     $this->commands->import('fruit_terms', ['idlist' => 'Apple'] + $this->importBaseOptions);
     $this->assertSame(1, $id_map->importedCount());
-    $this->commands->import('fruit_terms');
+    $this->commands->import('fruit_terms', []);
     $this->assertSame(3, $id_map->importedCount());
     $this->commands->import('fruit_terms', ['idlist' => 'Apple', 'update' => TRUE] + $this->importBaseOptions);
     $this->assertSame(0, count($id_map->getRowsNeedingUpdate(100)));
@@ -129,7 +129,7 @@ class DrushTest extends MigrateTestBase {
     $id_map = $migration->getIdMap();
     $id_map->saveMessage(['name' => 'Apple'], $message);
     /** @var \Consolidation\OutputFormatters\StructuredData\RowsOfFields $result */
-    $result = $this->commands->messages('fruit_terms');
+    $result = $this->commands->messages('fruit_terms', []);
     $rows = $result->getArrayCopy();
     $this->assertSame($message, $rows[0]['message']);
   }
@@ -143,7 +143,7 @@ class DrushTest extends MigrateTestBase {
     $migration = $this->migrationPluginManager->createInstance('fruit_terms');
     $id_map = $migration->getIdMap();
     $this->assertSame(3, $id_map->importedCount());
-    $this->commands->rollback('fruit_terms');
+    $this->commands->rollback('fruit_terms', []);
     $this->assertSame(0, $id_map->importedCount());
   }
 
@@ -156,7 +156,7 @@ class DrushTest extends MigrateTestBase {
     /** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
     $migration = $this->migrationPluginManager->createInstance('fruit_terms');
     $migration->setStatus(MigrationInterface::STATUS_IMPORTING);
-    $this->assertSame('Importing', $this->commands->status('fruit_terms')->getArrayCopy()[0]['status']);
+    $this->assertSame('Importing', $this->commands->status('fruit_terms', [])->getArrayCopy()[0]['status']);
     $this->commands->resetStatus('fruit_terms');
     $this->assertSame(MigrationInterface::STATUS_IDLE, $migration->getStatus());
 
-- 
Arne Jørgensen

