From 90e96bfc03082fbea766c4d2283533208f3fabe1 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Wed, 22 Nov 2017 08:46:49 -0500 Subject: [PATCH 1/3] Add task to the valid types. Ensure that the valid type options stays in sync with the support types by using the same data in both places. Refs #289 --- src/Shell/Task/TestTask.php | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/Shell/Task/TestTask.php b/src/Shell/Task/TestTask.php index 3057d0f61..feb24c132 100644 --- a/src/Shell/Task/TestTask.php +++ b/src/Shell/Task/TestTask.php @@ -708,24 +708,15 @@ public function getOptionParser() { $parser = parent::getOptionParser(); + $types = array_keys($this->classTypes); + $types = array_merge($types, array_map('strtolower', $types)); + $parser->setDescription( 'Bake test case skeletons for classes.' )->addArgument('type', [ 'help' => 'Type of class to bake, can be any of the following:' . ' controller, model, helper, component or behavior.', - 'choices' => [ - 'Controller', 'controller', - 'Table', 'table', - 'Entity', 'entity', - 'Helper', 'helper', - 'Component', 'component', - 'Behavior', 'behavior', - 'Shell', 'shell', - 'shell_helper', - 'Cell', 'cell', - 'Form', 'form', - 'Mailer', 'mailer', - ] + 'choices' => $types, ])->addArgument('name', [ 'help' => 'An existing class to bake tests for.' ])->addOption('fixtures', [ From 22d0d1b47a95b1d332575d57d9985d99103a6609 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Wed, 22 Nov 2017 08:54:57 -0500 Subject: [PATCH 2/3] Fix incorrect suggestion when test class name is missing. --- src/Shell/Task/TestTask.php | 6 +++--- tests/TestCase/Shell/Task/TestTaskTest.php | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Shell/Task/TestTask.php b/src/Shell/Task/TestTask.php index feb24c132..7c0f05869 100644 --- a/src/Shell/Task/TestTask.php +++ b/src/Shell/Task/TestTask.php @@ -145,9 +145,9 @@ public function outputTypeChoices() * @param string $type The typename to get classes for. * @return array */ - public function outputClassChoices($type) + public function outputClassChoices($typeName) { - $type = $this->mapType($type); + $type = $this->mapType($typeName); $this->out( 'You must provide a class to bake a test for. Some possible options are:', 2 @@ -158,7 +158,7 @@ public function outputClassChoices($type) $this->out(++$i . '. ' . $option); } $this->out(''); - $this->out('Re-run your command as `cake bake ' . $type . ' `'); + $this->out('Re-run your command as `cake bake ' . $typeName . ' `'); return $options; } diff --git a/tests/TestCase/Shell/Task/TestTaskTest.php b/tests/TestCase/Shell/Task/TestTaskTest.php index b08a71a4c..7c8489f99 100644 --- a/tests/TestCase/Shell/Task/TestTaskTest.php +++ b/tests/TestCase/Shell/Task/TestTaskTest.php @@ -197,6 +197,15 @@ public function testOutputClassOptionsForTable() 'CategoryThreadsTable' ]; + $this->io->expects($this->exactly(5)) + ->method('out') + ->withConsecutive( + ['You must provide a class to bake a test for. Some possible options are:', 2], + ['1. ArticlesTable'], + ['2. CategoryThreadsTable'], + [''], + ['Re-run your command as `cake bake Table `'] + ); $choices = $this->Task->outputClassChoices('Table'); $this->assertSame($expected, $choices); } From 4551fbe24f01158adff1a5006628abce592a8df5 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Wed, 22 Nov 2017 21:46:22 -0500 Subject: [PATCH 3/3] Fix doc string. --- src/Shell/Task/TestTask.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Shell/Task/TestTask.php b/src/Shell/Task/TestTask.php index 7c0f05869..1b5180cf3 100644 --- a/src/Shell/Task/TestTask.php +++ b/src/Shell/Task/TestTask.php @@ -142,7 +142,7 @@ public function outputTypeChoices() /** * Output a list of possible classnames you might want to generate a test for. * - * @param string $type The typename to get classes for. + * @param string $typeName The typename to get classes for. * @return array */ public function outputClassChoices($typeName)