Skip to content

Commit

Permalink
Dont use magic numbers for success code either.
Browse files Browse the repository at this point in the history
  • Loading branch information
dereuromark committed Dec 16, 2016
1 parent 4c545b9 commit 2bcfe5c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
9 changes: 8 additions & 1 deletion src/Console/Shell.php
Expand Up @@ -48,6 +48,13 @@ class Shell
*/
const CODE_ERROR = 1;

/**
* Default success code
*
* @var int
*/
const CODE_SUCCESS = 0;

/**
* Output constant making verbose shells.
*
Expand Down Expand Up @@ -881,7 +888,7 @@ public function helper($name, array $settings = [])
* @throws \Cake\Console\Exception\StopException
* @return void
*/
protected function _stop($status = 0)
protected function _stop($status = self::CODE_SUCCESS)
{
throw new StopException('Halting error reached', $status);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Console/ShellDispatcher.php
Expand Up @@ -184,10 +184,10 @@ public function dispatch($extra = [])
return $e->getCode();
}
if ($result === null || $result === true) {
return 0;
return Shell::CODE_SUCCESS;
}

return 1;
return Shell::CODE_ERROR;
}

/**
Expand Down
13 changes: 7 additions & 6 deletions tests/TestCase/Console/ShellDispatcherTest.php
Expand Up @@ -14,6 +14,7 @@
*/
namespace Cake\Test\TestCase\Console;

use Cake\Console\Shell;
use Cake\Console\ShellDispatcher;
use Cake\Core\Configure;
use Cake\Core\Plugin;
Expand Down Expand Up @@ -204,12 +205,12 @@ public function testDispatchShellWithMain()

$dispatcher->args = ['mock_with_main'];
$result = $dispatcher->dispatch();
$this->assertSame(0, $result);
$this->assertSame(Shell::CODE_SUCCESS, $result);
$this->assertEquals([], $dispatcher->args);

$dispatcher->args = ['mock_with_main'];
$result = $dispatcher->dispatch();
$this->assertSame(0, $result);
$this->assertSame(Shell::CODE_SUCCESS, $result);
$this->assertEquals([], $dispatcher->args);
}

Expand Down Expand Up @@ -237,7 +238,7 @@ public function testDispatchShellWithoutMain()

$dispatcher->args = ['mock_without_main', 'initdb'];
$result = $dispatcher->dispatch();
$this->assertEquals(0, $result);
$this->assertEquals(Shell::CODE_SUCCESS, $result);
}

/**
Expand All @@ -264,7 +265,7 @@ public function testDispatchShortPluginAlias()

$dispatcher->args = ['example'];
$result = $dispatcher->dispatch();
$this->assertEquals(0, $result);
$this->assertEquals(Shell::CODE_SUCCESS, $result);
}

/**
Expand All @@ -291,7 +292,7 @@ public function testDispatchShortPluginAliasCamelized()

$dispatcher->args = ['Example'];
$result = $dispatcher->dispatch();
$this->assertEquals(0, $result);
$this->assertEquals(Shell::CODE_SUCCESS, $result);
}

/**
Expand All @@ -318,7 +319,7 @@ public function testDispatchShortPluginAliasConflict()

$dispatcher->args = ['sample'];
$result = $dispatcher->dispatch();
$this->assertEquals(0, $result);
$this->assertEquals(Shell::CODE_SUCCESS, $result);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Console/ShellTest.php
Expand Up @@ -67,7 +67,7 @@ class ShellTestShell extends Shell
* @param int $status
* @return void
*/
protected function _stop($status = 0)
protected function _stop($status = Shell::CODE_SUCCESS)
{
$this->stopped = $status;
}
Expand Down Expand Up @@ -991,7 +991,7 @@ public function testRunCommandWithMissingMethodInSubcommands()
*
* @return void
*/
public function testRunCommandBaseclassMethod()
public function testRunCommandBaseClassMethod()
{
$shell = $this->getMockBuilder('Cake\Console\Shell')
->setMethods(['startup', 'getOptionParser', 'out', 'hr'])
Expand Down

0 comments on commit 2bcfe5c

Please sign in to comment.