Skip to content

Commit

Permalink
Fix backwards compatibility with CommandRunner.
Browse files Browse the repository at this point in the history
In making the new runner stricter, I dropped the inflection on command
names.

Refs #11174
  • Loading branch information
markstory committed Sep 13, 2017
1 parent 6829ddd commit f74123b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Console/CommandRunner.php
Expand Up @@ -23,6 +23,7 @@
use Cake\Event\EventManagerTrait;
use Cake\Shell\HelpShell;
use Cake\Shell\VersionShell;
use Cake\Utility\Inflector;
use RuntimeException;

/**
Expand Down Expand Up @@ -169,6 +170,9 @@ protected function getShell(ConsoleIo $io, CommandCollection $commands, $name)
if (isset($this->aliases[$name])) {
$name = $this->aliases[$name];
}
if (!$commands->has($name)) {
$name = Inflector::underscore($name);
}
if (!$commands->has($name)) {
throw new RuntimeException(
"Unknown command `{$this->root} {$name}`." .
Expand Down
23 changes: 23 additions & 0 deletions tests/TestCase/Console/CommandRunnerTest.php
Expand Up @@ -208,6 +208,29 @@ public function testRunValidCommand()
$this->assertContains('URI template', $contents);
}

/**
* Test running a valid command and that backwards compatible
* inflection is hooked up.
*
* @return void
*/
public function testRunValidCommandInflection()
{
$app = $this->getMockBuilder(BaseApplication::class)
->setMethods(['middleware', 'bootstrap'])
->setConstructorArgs([$this->config])
->getMock();

$output = new ConsoleOutput();

$runner = new CommandRunner($app, 'cake');
$result = $runner->run(['cake', 'OrmCache', 'build'], $this->getMockIo($output));
$this->assertSame(Shell::CODE_SUCCESS, $result);

$contents = implode("\n", $output->messages());
$this->assertContains('Cache', $contents);
}

/**
* Test running a valid raising an error
*
Expand Down

0 comments on commit f74123b

Please sign in to comment.