Skip to content

Commit

Permalink
Add assertions for error codes to routes shell.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Aug 26, 2017
1 parent 07640f8 commit 7c76081
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions tests/TestCase/Shell/RoutesShellTest.php
Expand Up @@ -14,6 +14,7 @@
*/
namespace Cake\Test\TestCase\Shell;

use Cake\Console\Shell;
use Cake\Routing\Router;
use Cake\Shell\RoutesShell;
use Cake\TestSuite\ConsoleIntegrationTestCase;
Expand Down Expand Up @@ -48,22 +49,6 @@ public function tearDown()
Router::reload();
}

/**
* Check that a row of cells exists in the output.
*
* @param array $row The row of cells to check
* @return void
*/
protected function assertOutputContainsRow(array $row)
{
$row = array_map(function ($cell) {
return preg_quote($cell, '/');
}, $row);
$cells = implode('\s+\|\s+', $row);
$pattern = '/' . $cells . '/';
$this->assertOutputRegexp($pattern);
}

/**
* Test checking an non-existing route.
*
Expand All @@ -72,6 +57,7 @@ protected function assertOutputContainsRow(array $row)
public function testMain()
{
$this->exec('routes');
$this->assertExitCode(Shell::CODE_SUCCESS);
$this->assertOutputContainsRow([
'<info>Route name</info>',
'<info>URI template</info>',
Expand Down Expand Up @@ -102,6 +88,7 @@ public function testMain()
public function testCheck()
{
$this->exec('routes check /articles/check');
$this->assertExitCode(Shell::CODE_SUCCESS);
$this->assertOutputContainsRow([
'<info>Route name</info>',
'<info>URI template</info>',
Expand All @@ -122,6 +109,7 @@ public function testCheck()
public function testCheckWithNamedRoute()
{
$this->exec('routes check /tests/index');
$this->assertExitCode(Shell::CODE_SUCCESS);
$this->assertOutputContainsRow([
'<info>Route name</info>',
'<info>URI template</info>',
Expand All @@ -142,6 +130,7 @@ public function testCheckWithNamedRoute()
public function testCheckNotFound()
{
$this->exec('routes check /nope');
$this->assertExitCode(Shell::CODE_ERROR);
$this->assertErrorContains('did not match');
}

Expand All @@ -153,6 +142,7 @@ public function testCheckNotFound()
public function testGenerateNoPassArgs()
{
$this->exec('routes generate controller:Articles action:index');
$this->assertExitCode(Shell::CODE_SUCCESS);
$this->assertOutputContains('> /articles/index');
$this->assertErrorEmpty();
}
Expand All @@ -165,6 +155,7 @@ public function testGenerateNoPassArgs()
public function testGeneratePassedArguments()
{
$this->exec('routes generate controller:Articles action:view 2 3');
$this->assertExitCode(Shell::CODE_SUCCESS);
$this->assertOutputContains('> /articles/view/2/3');
$this->assertErrorEmpty();
}
Expand All @@ -177,6 +168,7 @@ public function testGeneratePassedArguments()
public function testGenerateBoolParams()
{
$this->exec('routes generate controller:Articles action:index _ssl:true _host:example.com');
$this->assertExitCode(Shell::CODE_SUCCESS);
$this->assertOutputContains('> https://example.com/articles/index');
}

Expand All @@ -188,6 +180,7 @@ public function testGenerateBoolParams()
public function testGenerateMissing()
{
$this->exec('routes generate controller:Derp');
$this->assertExitCode(Shell::CODE_ERROR);
$this->assertErrorContains('do not match');
}
}

0 comments on commit 7c76081

Please sign in to comment.