Browse Source

Fix console integration tests with required arguments

Corey Taylor 4 years ago
parent
commit
13ad1487b0

+ 13 - 1
tests/TestCase/TestSuite/ConsoleIntegrationTestTraitTest.php

@@ -107,7 +107,7 @@ class ConsoleIntegrationTestTraitTest extends TestCase
      */
     public function testExecWithJsonArg(): void
     {
-        $this->exec("integration args_and_options '{\"key\":\"value\"}'");
+        $this->exec("integration '{\"key\":\"value\"}'");
 
         $this->assertErrorEmpty();
         $this->assertOutputContains('arg: {"key":"value"}');
@@ -115,6 +115,18 @@ class ConsoleIntegrationTestTraitTest extends TestCase
     }
 
     /**
+     * tests exec with missing required argument
+     */
+    public function testExecWithMissingRequiredArg(): void
+    {
+        $this->exec('integration');
+
+        $this->assertErrorContains('Missing required argument');
+        $this->assertErrorContains('`arg` argument is required');
+        $this->assertExitCode(Command::CODE_ERROR);
+    }
+
+    /**
      * tests exec with input
      */
     public function testExecWithInput(): void

+ 4 - 1
tests/test_app/TestApp/Command/IntegrationCommand.php

@@ -18,7 +18,10 @@ class IntegrationCommand extends Command
 
     public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser
     {
-        $parser->addArgument('arg')
+        $parser
+            ->addArgument('arg', [
+                'required' => true,
+            ])
             ->addOption('opt', [
                 'short' => 'o',
             ]);