Navigation Menu

Skip to content

Commit

Permalink
Update HelpShell tests to use ConsoleIntegrationTestCase
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Sep 4, 2017
1 parent 30029f2 commit c48ae8e
Showing 1 changed file with 23 additions and 39 deletions.
62 changes: 23 additions & 39 deletions tests/TestCase/Shell/HelpShellTest.php
Expand Up @@ -14,17 +14,14 @@
*/
namespace Cake\Test\TestCase\Shell;

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

/**
* HelpShell test.
*/
class HelpShellTest extends TestCase
class HelpShellTest extends ConsoleIntegrationTestCase
{
/**
* setup method
Expand All @@ -35,16 +32,8 @@ public function setUp()
{
parent::setUp();
$this->setAppNamespace();
$this->useCommandRunner(true);
Plugin::load('TestPlugin');

$this->out = new ConsoleOutput();
$this->err = new ConsoleOutput();
$this->io = new ConsoleIo($this->out, $this->err);
$this->shell = new HelpShell($this->io);

$commands = new CommandCollection();
$commands->addMany($commands->autoDiscover());
$this->shell->setCommandCollection($commands);
}

/**
Expand All @@ -54,11 +43,9 @@ public function setUp()
*/
public function testMainNoCommandsFallback()
{
$shell = new HelpShell($this->io);
$this->assertNull($shell->main());

$output = implode("\n", $this->out->messages());
$this->assertOutput($output);
$this->exec('help');
$this->assertExitCode(Shell::CODE_SUCCESS);
$this->assertCommandList();
}

/**
Expand All @@ -68,10 +55,9 @@ public function testMainNoCommandsFallback()
*/
public function testMain()
{
$this->assertNull($this->shell->main());

$output = implode("\n", $this->out->messages());
$this->assertOutput($output);
$this->exec('help');
$this->assertExitCode(Shell::CODE_SUCCESS);
$this->assertCommandList();
}

/**
Expand All @@ -80,14 +66,14 @@ public function testMain()
* @param string $output The output to check.
* @return void
*/
protected function assertOutput($output)
protected function assertCommandList()
{
$this->assertContains('- sample', $output, 'app shell');
$this->assertContains('- test_plugin.sample', $output, 'Long plugin name');
$this->assertContains('- routes', $output, 'core shell');
$this->assertContains('- test_plugin.example', $output, 'Long plugin name');
$this->assertContains('To run a command', $output, 'more info present');
$this->assertContains('To get help', $output, 'more info present');
$this->assertOutputContains('- sample', 'app shell');
$this->assertOutputContains('- test_plugin.sample', 'Long plugin name');
$this->assertOutputContains('- routes', 'core shell');
$this->assertOutputContains('- test_plugin.example', 'Long plugin name');
$this->assertOutputContains('To run a command', 'more info present');
$this->assertOutputContains('To get help', 'more info present');
}

/**
Expand All @@ -97,19 +83,17 @@ protected function assertOutput($output)
*/
public function testMainAsXml()
{
$this->shell->params['xml'] = true;
$this->shell->main();
$output = implode("\n", $this->out->messages());

$this->assertContains('<shells>', $output);
$this->exec('help --xml');
$this->assertExitCode(Shell::CODE_SUCCESS);
$this->assertOutputContains('<shells>');

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

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

$find = '<shell name="test_plugin.sample" call_as="test_plugin.sample" provider="TestPlugin\Shell\SampleShell" help="test_plugin.sample -h"';
$this->assertContains($find, $output);
$this->assertOutputContains($find);
}
}

0 comments on commit c48ae8e

Please sign in to comment.