Skip to content

Commit

Permalink
Update CommandListShell to use integration test case.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Sep 4, 2017
1 parent 3f9caaa commit 30029f2
Showing 1 changed file with 25 additions and 44 deletions.
69 changes: 25 additions & 44 deletions tests/TestCase/Shell/CommandListShellTest.php
Expand Up @@ -14,16 +14,15 @@
*/
namespace Cake\Test\TestCase\Shell;

use Cake\Console\ConsoleIo;
use Cake\Console\Shell;
use Cake\Core\Configure;
use Cake\Core\Plugin;
use Cake\TestSuite\Stub\ConsoleOutput;
use Cake\TestSuite\TestCase;
use Cake\TestSuite\ConsoleIntegrationTestCase;

/**
* CommandListShellTest
*/
class CommandListShellTest extends TestCase
class CommandListShellTest extends ConsoleIntegrationTestCase
{

/**
Expand All @@ -35,19 +34,6 @@ public function setUp()
{
parent::setUp();
Plugin::load(['TestPlugin', 'TestPluginTwo']);

$this->out = new ConsoleOutput();
$io = new ConsoleIo($this->out);

$this->Shell = $this->getMockBuilder('Cake\Shell\CommandListShell')
->setMethods(['in', 'err', '_stop', 'clear'])
->setConstructorArgs([$io])
->getMock();

$this->Shell->Command = $this->getMockBuilder('Cake\Shell\Task\CommandTask')
->setMethods(['in', '_stop', 'err', 'clear'])
->setConstructorArgs([$io])
->getMock();
}

/**
Expand All @@ -58,7 +44,6 @@ public function setUp()
public function tearDown()
{
parent::tearDown();
unset($this->Shell);
Plugin::unload();
}

Expand All @@ -69,21 +54,21 @@ public function tearDown()
*/
public function testMain()
{
$this->Shell->main();
$output = $this->out->messages();
$output = implode("\n", $output);
$this->exec('command_list');

$expected = "/\[.*TestPlugin.*\] example/";
$this->assertRegExp($expected, $output);
$this->assertOutputRegExp($expected);

$expected = "/\[.*TestPluginTwo.*\] example, unique, welcome/";
$this->assertRegExp($expected, $output);
$this->assertOutputRegExp($expected);

$expected = "/\[.*CORE.*\] cache, help, i18n, orm_cache, plugin, routes, server/";
$this->assertRegExp($expected, $output);
$this->assertOutputRegExp($expected);

$expected = "/\[.*app.*\] i18m, integration, sample/";
$this->assertRegExp($expected, $output);
$this->assertOutputRegExp($expected);
$this->assertExitCode(Shell::CODE_SUCCESS);
$this->assertErrorEmpty();
}

/**
Expand All @@ -95,16 +80,16 @@ public function testMain()
public function testMainAppPriority()
{
rename(APP . 'Shell' . DS . 'I18mShell.php', APP . 'Shell' . DS . 'I18nShell.php');
$this->Shell->main();
$output = $this->out->messages();
$output = implode("\n", $output);
$this->exec('command_list');
rename(APP . 'Shell' . DS . 'I18nShell.php', APP . 'Shell' . DS . 'I18mShell.php');

$expected = "/\[.*CORE.*\] cache, help, orm_cache, plugin, routes, server/";
$this->assertRegExp($expected, $output);
$this->assertOutputRegExp($expected);

$expected = "/\[.*app.*\] i18n, integration, sample/";
$this->assertRegExp($expected, $output);
$this->assertOutputRegExp($expected);
$this->assertExitCode(Shell::CODE_SUCCESS);
$this->assertErrorEmpty();
}

/**
Expand All @@ -114,20 +99,18 @@ public function testMainAppPriority()
*/
public function testMainXml()
{
$this->Shell->params['xml'] = true;
$this->Shell->main();

$output = $this->out->messages();
$output = implode("\n", $output);
$this->exec('command_list --xml');

$find = '<shell name="sample" call_as="sample" provider="app" help="sample -h"';
$this->assertContains($find, $output);
$this->assertOutputContains($find);

$find = '<shell name="orm_cache" call_as="orm_cache" provider="CORE" help="orm_cache -h"';
$this->assertContains($find, $output);
$this->assertOutputContains($find);

$find = '<shell name="welcome" call_as="TestPluginTwo.welcome" provider="TestPluginTwo" help="TestPluginTwo.welcome -h"';
$this->assertContains($find, $output);
$this->assertOutputContains($find);
$this->assertExitCode(Shell::CODE_SUCCESS);
$this->assertErrorEmpty();
}

/**
Expand All @@ -137,12 +120,10 @@ public function testMainXml()
*/
public function testMainVersion()
{
$this->Shell->params['version'] = true;
$this->Shell->main();
$output = $this->out->messages();
$output = implode("\n", $output);

$this->exec('command_list --version');
$expected = Configure::version();
$this->assertEquals($expected, $output);
$this->assertOutputContains($expected);
$this->assertExitCode(Shell::CODE_SUCCESS);
$this->assertErrorEmpty();
}
}

0 comments on commit 30029f2

Please sign in to comment.