Browse Source

Add tests for Argument type checks

Refs #17589
Mark Story 2 years ago
parent
commit
a7e7c54d72
1 changed files with 37 additions and 0 deletions
  1. 37 0
      tests/TestCase/Console/ArgumentsTest.php

+ 37 - 0
tests/TestCase/Console/ArgumentsTest.php

@@ -17,6 +17,7 @@ declare(strict_types=1);
 namespace Cake\Test\TestCase\Console;
 
 use Cake\Console\Arguments;
+use Cake\Console\Exception\ConsoleException;
 use Cake\TestSuite\TestCase;
 
 /**
@@ -152,6 +153,19 @@ class ArgumentsTest extends TestCase
         $this->assertNull($args->getOption('undef'));
     }
 
+    /**
+     * test getOption() checks types
+     */
+    public function testGetOptionInvalidType(): void
+    {
+        $options = [
+            'list' => [1, 2],
+        ];
+        $args = new Arguments([], $options, []);
+        $this->expectException(ConsoleException::class);
+        $args->getOption('list');
+    }
+
     public function testGetBooleanOption(): void
     {
         $options = [
@@ -162,6 +176,19 @@ class ArgumentsTest extends TestCase
         $this->assertNull($args->getBooleanOption('missing'));
     }
 
+    /**
+     * test getOption() checks types
+     */
+    public function testGetOptionBooleanInvalidType(): void
+    {
+        $options = [
+            'list' => [1, 2],
+        ];
+        $args = new Arguments([], $options, []);
+        $this->expectException(ConsoleException::class);
+        $args->getBooleanOption('list');
+    }
+
     public function testGetMultipleOption(): void
     {
         $options = [
@@ -171,4 +198,14 @@ class ArgumentsTest extends TestCase
         $this->assertSame(['one', 'two', 'three'], $args->getMultipleOption('types'));
         $this->assertNull($args->getMultipleOption('missing'));
     }
+
+    public function testGetMultipleOptionInvalidType(): void
+    {
+        $options = [
+            'connection' => 'test',
+        ];
+        $args = new Arguments([], $options, []);
+        $this->expectException(ConsoleException::class);
+        $args->getMultipleOption('connection');
+    }
 }