|
|
@@ -21,6 +21,7 @@ use Cake\ORM\Locator\TableLocator;
|
|
|
use Cake\ORM\Table;
|
|
|
use Cake\TestSuite\Stub\ConsoleOutput;
|
|
|
use Cake\TestSuite\TestCase;
|
|
|
+use InvalidArgumentException;
|
|
|
use TestApp\Command\AutoLoadModelCommand;
|
|
|
use TestApp\Command\DemoCommand;
|
|
|
|
|
|
@@ -273,6 +274,88 @@ class CommandTest extends TestCase
|
|
|
$command->abort(99);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * test executeCommand with a string class
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testExecuteCommandString()
|
|
|
+ {
|
|
|
+ $output = new ConsoleOutput();
|
|
|
+ $command = new Command();
|
|
|
+ $result = $command->executeCommand(DemoCommand::class, $this->getMockIo($output));
|
|
|
+ $this->assertNull($result);
|
|
|
+ $this->assertEquals(['Quiet!', 'Demo Command!'], $output->messages());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * test executeCommand with an invalid string class
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testExecuteCommandStringInvalid()
|
|
|
+ {
|
|
|
+ $this->expectException(InvalidArgumentException::class);
|
|
|
+ $this->expectExceptionMessage("Command class 'Nope' does not exist");
|
|
|
+
|
|
|
+ $command = new Command();
|
|
|
+ $command->executeCommand('Nope', $this->getMockIo(new ConsoleOutput()));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * test executeCommand with arguments
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testExecuteCommandArguments()
|
|
|
+ {
|
|
|
+ $output = new ConsoleOutput();
|
|
|
+ $command = new Command();
|
|
|
+ $command->executeCommand(DemoCommand::class, $this->getMockIo($output), ['Jane']);
|
|
|
+ $this->assertEquals(['Quiet!', 'Demo Command!', 'Jane'], $output->messages());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * test executeCommand with arguments
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testExecuteCommandArgumentsOptions()
|
|
|
+ {
|
|
|
+ $output = new ConsoleOutput();
|
|
|
+ $command = new Command();
|
|
|
+ $command->executeCommand(DemoCommand::class, $this->getMockIo($output), ['--quiet', 'Jane']);
|
|
|
+ $this->assertEquals(['Quiet!'], $output->messages());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * test executeCommand with an instance
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testExecuteCommandInstance()
|
|
|
+ {
|
|
|
+ $output = new ConsoleOutput();
|
|
|
+ $command = new Command();
|
|
|
+ $result = $command->executeCommand(new DemoCommand(), $this->getMockIo($output));
|
|
|
+ $this->assertNull($result);
|
|
|
+ $this->assertEquals(['Quiet!', 'Demo Command!'], $output->messages());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * test executeCommand with an invalid instance
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testExecuteCommandInstanceInvalid()
|
|
|
+ {
|
|
|
+ $this->expectException(InvalidArgumentException::class);
|
|
|
+ $this->expectExceptionMessage("Command 'stdClass' is not a subclass");
|
|
|
+
|
|
|
+ $command = new Command();
|
|
|
+ $command->executeCommand(new \stdClass, $this->getMockIo(new ConsoleOutput()));
|
|
|
+ }
|
|
|
+
|
|
|
protected function getMockIo($output)
|
|
|
{
|
|
|
$io = $this->getMockBuilder(ConsoleIo::class)
|