Skip to content

Commit

Permalink
Convert loadtask test to integration style.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Mar 2, 2018
1 parent 48b500e commit 1b53551
Showing 1 changed file with 50 additions and 84 deletions.
134 changes: 50 additions & 84 deletions tests/TestCase/Shell/Task/LoadTaskTest.php
Expand Up @@ -13,14 +13,15 @@
*/
namespace Cake\Test\TestCase\Shell\Task;

use Cake\Console\Shell;
use Cake\Core\Plugin;
use Cake\Filesystem\File;
use Cake\TestSuite\TestCase;
use Cake\TestSuite\ConsoleIntegrationTestCase;

/**
* LoadTaskTest class.
*/
class LoadTaskTest extends TestCase
class LoadTaskTest extends ConsoleIntegrationTestCase
{
/**
* @var \Cake\Shell\Task\LoadTask|\PHPUnit_Framework_MockObject_MockObject
Expand All @@ -45,12 +46,16 @@ public function setUp()
->setConstructorArgs([$this->io])
->getMock();

$this->app = APP . DS . 'Application.php';
$this->bootstrap = ROOT . DS . 'config' . DS . 'bootstrap.php';
$this->bootstrapCli = ROOT . DS . 'config' . DS . 'bootstrap_cli.php';
copy($this->bootstrap, $this->bootstrapCli);

$bootstrap = new File($this->bootstrap, false);
$this->originalBootstrapContent = $bootstrap->read();

$app = new File($this->app, false);
$this->originalAppContent = $app->read();
}

/**
Expand All @@ -67,6 +72,9 @@ public function tearDown()
$bootstrap = new File($this->bootstrap, false);
$bootstrap->write($this->originalBootstrapContent);
unlink($this->bootstrapCli);

$app = new File($this->app, false);
$app->write($this->originalAppContent);
}

/**
Expand All @@ -76,20 +84,14 @@ public function tearDown()
*/
public function testLoad()
{
$this->Task->params = [
'bootstrap' => false,
'routes' => false,
'autoload' => true,
'cli' => false
];

$action = $this->Task->main('TestPlugin');

$this->assertTrue($action);

$expected = "Plugin::load('TestPlugin', ['autoload' => true]);";
$bootstrap = new File($this->bootstrap, false);
$this->assertContains($expected, $bootstrap->read());
$this->exec('plugin load --no_app --autoload TestPlugin');
$this->assertExitCode(Shell::CODE_SUCCESS);

$contents = file_get_contents($this->bootstrap);
$this->assertContains(
"Plugin::load('TestPlugin', ['autoload' => true]);",
$contents
);
}

/**
Expand All @@ -99,20 +101,14 @@ public function testLoad()
*/
public function testLoadWithBootstrap()
{
$this->Task->params = [
'bootstrap' => true,
'routes' => false,
'autoload' => true,
'cli' => false
];

$action = $this->Task->main('TestPlugin');

$this->assertTrue($action);

$expected = "Plugin::load('TestPlugin', ['autoload' => true, 'bootstrap' => true]);";
$bootstrap = new File($this->bootstrap, false);
$this->assertContains($expected, $bootstrap->read());
$this->exec('plugin load --no_app --bootstrap --autoload TestPlugin');
$this->assertExitCode(Shell::CODE_SUCCESS);

$contents = file_get_contents($this->bootstrap);
$this->assertContains(
"Plugin::load('TestPlugin', ['autoload' => true, 'bootstrap' => true]);",
$contents
);
}

/**
Expand All @@ -122,20 +118,14 @@ public function testLoadWithBootstrap()
*/
public function testLoadBootstrapCli()
{
$this->Task->params = [
'bootstrap' => false,
'routes' => false,
'autoload' => false,
'cli' => true
];

$action = $this->Task->main('CliPlugin');

$this->assertTrue($action);

$expected = "Plugin::load('CliPlugin');";
$bootstrap = new File($this->bootstrapCli, false);
$this->assertContains($expected, $bootstrap->read());
$this->exec('plugin load --no_app --cli TestPlugin');
$this->assertExitCode(Shell::CODE_SUCCESS);

$contents = file_get_contents($this->bootstrapCli);
$this->assertContains(
"Plugin::load('TestPlugin');",
$contents
);
}

/**
Expand All @@ -145,20 +135,14 @@ public function testLoadBootstrapCli()
*/
public function testLoadWithRoutes()
{
$this->Task->params = [
'bootstrap' => false,
'routes' => true,
'autoload' => true,
'cli' => false
];

$action = $this->Task->main('TestPlugin');

$this->assertTrue($action);

$expected = "Plugin::load('TestPlugin', ['autoload' => true, 'routes' => true]);";
$bootstrap = new File($this->bootstrap, false);
$this->assertContains($expected, $bootstrap->read());
$this->exec('plugin load --no_app --routes --autoload TestPlugin');
$this->assertExitCode(Shell::CODE_SUCCESS);

$contents = file_get_contents($this->bootstrap);
$this->assertContains(
"Plugin::load('TestPlugin', ['autoload' => true, 'routes' => true]);",
$contents
);
}

/**
Expand All @@ -168,20 +152,11 @@ public function testLoadWithRoutes()
*/
public function testLoadNoAutoload()
{
$this->Task->params = [
'bootstrap' => false,
'routes' => true,
'autoload' => false,
'cli' => false
];

$action = $this->Task->main('TestPlugin');
$this->exec('plugin load --no_app --routes TestPlugin');
$this->assertExitCode(Shell::CODE_SUCCESS);

$this->assertTrue($action);

$expected = "Plugin::load('TestPlugin', ['routes' => true]);";
$bootstrap = new File($this->bootstrap, false);
$this->assertContains($expected, $bootstrap->read());
$contents = file_get_contents($this->bootstrap);
$this->assertContains("Plugin::load('TestPlugin', ['routes' => true]);", $contents);
}

/**
Expand All @@ -191,19 +166,10 @@ public function testLoadNoAutoload()
*/
public function testLoadNothing()
{
$this->Task->params = [
'bootstrap' => false,
'routes' => false,
'autoload' => false,
'cli' => false
];

$action = $this->Task->main('TestPlugin');
$this->exec('plugin load --no_app TestPlugin');
$this->assertExitCode(Shell::CODE_SUCCESS);

$this->assertTrue($action);

$expected = "Plugin::load('TestPlugin');";
$bootstrap = new File($this->bootstrap, false);
$this->assertContains($expected, $bootstrap->read());
$contents = file_get_contents($this->bootstrap);
$this->assertContains("Plugin::load('TestPlugin');", $contents);
}
}

0 comments on commit 1b53551

Please sign in to comment.