|
|
@@ -20,78 +20,11 @@ use Cake\Console\Shell;
|
|
|
use Cake\Core\Plugin;
|
|
|
use Cake\Filesystem\Folder;
|
|
|
use Cake\TestSuite\TestCase;
|
|
|
+use TestApp\Shell\MergeShell;
|
|
|
+use TestApp\Shell\ShellTestShell;
|
|
|
use TestApp\Shell\TestingDispatchShell;
|
|
|
|
|
|
/**
|
|
|
- * for testing merging vars
|
|
|
- */
|
|
|
-class MergeShell extends Shell
|
|
|
-{
|
|
|
-
|
|
|
- public $tasks = ['Command', 'Extract'];
|
|
|
-
|
|
|
- public $modelClass = 'Articles';
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * ShellTestShell class
|
|
|
- */
|
|
|
-class ShellTestShell extends Shell
|
|
|
-{
|
|
|
-
|
|
|
- /**
|
|
|
- * name property
|
|
|
- *
|
|
|
- * @var string
|
|
|
- */
|
|
|
- public $name = 'ShellTestShell';
|
|
|
-
|
|
|
- /**
|
|
|
- * stopped property
|
|
|
- *
|
|
|
- * @var int
|
|
|
- */
|
|
|
- public $stopped;
|
|
|
-
|
|
|
- /**
|
|
|
- * testMessage property
|
|
|
- *
|
|
|
- * @var string
|
|
|
- */
|
|
|
- public $testMessage = 'all your base are belong to us';
|
|
|
-
|
|
|
- /**
|
|
|
- * stop method
|
|
|
- *
|
|
|
- * @param int $status
|
|
|
- * @return void
|
|
|
- */
|
|
|
- protected function _stop($status = Shell::CODE_SUCCESS)
|
|
|
- {
|
|
|
- $this->stopped = $status;
|
|
|
- }
|
|
|
-
|
|
|
- protected function _secret()
|
|
|
- {
|
|
|
- }
|
|
|
-
|
|
|
- //@codingStandardsIgnoreStart
|
|
|
- public function doSomething()
|
|
|
- {
|
|
|
- }
|
|
|
-
|
|
|
- protected function noAccess()
|
|
|
- {
|
|
|
- }
|
|
|
-
|
|
|
- public function logSomething()
|
|
|
- {
|
|
|
- $this->log($this->testMessage);
|
|
|
- }
|
|
|
- //@codingStandardsIgnoreEnd
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
* TestAppleTask class
|
|
|
*/
|
|
|
class TestAppleTask extends Shell
|
|
|
@@ -129,6 +62,14 @@ class ShellTest extends TestCase
|
|
|
'core.users'
|
|
|
];
|
|
|
|
|
|
+ /** @var \Cake\Console\Shell */
|
|
|
+ protected $Shell;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @var \Cake\Console\ConsoleIo|\PHPUnit\Framework\MockObject\MockObject
|
|
|
+ */
|
|
|
+ protected $io;
|
|
|
+
|
|
|
/**
|
|
|
* setUp method
|
|
|
*
|
|
|
@@ -580,6 +521,8 @@ class ShellTest extends TestCase
|
|
|
new Folder($path, true);
|
|
|
|
|
|
$contents = "<?php{$eol}echo 'test';${eol}\$te = 'st';{$eol}";
|
|
|
+
|
|
|
+ $this->Shell->interactive = false;
|
|
|
$result = $this->Shell->createFile($file, $contents);
|
|
|
$this->assertTrue($result);
|
|
|
$this->assertFileExists($file);
|
|
|
@@ -587,6 +530,30 @@ class ShellTest extends TestCase
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * Test that while in non interactive mode it will not overwrite files by default.
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testCreateFileNonInteractiveFileExists()
|
|
|
+ {
|
|
|
+ $eol = PHP_EOL;
|
|
|
+ $path = TMP . 'shell_test';
|
|
|
+ $file = $path . DS . 'file1.php';
|
|
|
+ if (!is_dir($path)) {
|
|
|
+ mkdir($path, 0770, true);
|
|
|
+ }
|
|
|
+ touch($file);
|
|
|
+ $this->assertFileExists($file);
|
|
|
+
|
|
|
+ new Folder($path, true);
|
|
|
+
|
|
|
+ $contents = "<?php{$eol}echo 'test';${eol}\$te = 'st';{$eol}";
|
|
|
+ $this->Shell->interactive = false;
|
|
|
+ $result = $this->Shell->createFile($file, $contents);
|
|
|
+ $this->assertFalse($result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* Test that files are not changed with a 'n' reply.
|
|
|
*
|
|
|
* @return void
|
|
|
@@ -641,7 +608,8 @@ class ShellTest extends TestCase
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Test that there is no user prompt in non-interactive mode while file already exists.
|
|
|
+ * Test that there is no user prompt in non-interactive mode while file already exists
|
|
|
+ * and if force mode is explicitly enabled.
|
|
|
*
|
|
|
* @return void
|
|
|
*/
|
|
|
@@ -657,6 +625,7 @@ class ShellTest extends TestCase
|
|
|
|
|
|
$this->io->expects($this->never())->method('askChoice');
|
|
|
|
|
|
+ $this->Shell->params['force'] = true;
|
|
|
$this->Shell->interactive = false;
|
|
|
$result = $this->Shell->createFile($file, 'My content');
|
|
|
$this->assertTrue($result);
|
|
|
@@ -1052,6 +1021,7 @@ TEXT;
|
|
|
*/
|
|
|
public function testRunCommandWithMissingMethodInSubcommands()
|
|
|
{
|
|
|
+ /** @var \Cake\Console\ConsoleOptionParser|\PHPUnit\Framework\MockObject\MockObject $parser */
|
|
|
$parser = $this->getMockBuilder('Cake\Console\ConsoleOptionParser')
|
|
|
->setMethods(['help'])
|
|
|
->setConstructorArgs(['knife'])
|
|
|
@@ -1059,6 +1029,7 @@ TEXT;
|
|
|
$parser->addSubCommand('slice');
|
|
|
|
|
|
$io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock();
|
|
|
+ /** @var \Cake\Console\Shell|\PHPUnit\Framework\MockObject\MockObject $shell */
|
|
|
$shell = $this->getMockBuilder('Cake\Console\Shell')
|
|
|
->setMethods(['getOptionParser', 'startup'])
|
|
|
->setConstructorArgs([$io])
|
|
|
@@ -1418,7 +1389,7 @@ TEXT;
|
|
|
->method('setLoggers')
|
|
|
->with(ConsoleIo::QUIET);
|
|
|
|
|
|
- $this->Shell = $this->getMockBuilder(__NAMESPACE__ . '\ShellTestShell')
|
|
|
+ $this->Shell = $this->getMockBuilder(ShellTestShell::class)
|
|
|
->setMethods(['welcome'])
|
|
|
->setConstructorArgs([$io])
|
|
|
->getMock();
|