Browse Source

Merge branch 'master' into 3.next

Mark Story 7 years ago
parent
commit
a3bc982647

+ 1 - 0
.gitignore

@@ -7,6 +7,7 @@
 /phpunit.xml
 /phpcs.xml
 /vendor
+/composer.phar
 *.mo
 debug.log
 error.log

+ 4 - 4
src/Command/HelpCommand.php

@@ -44,7 +44,7 @@ class HelpCommand extends Command implements CommandCollectionAwareInterface
     }
 
     /**
-     * Main function Prints out the list of shells.
+     * Main function Prints out the list of commands.
      *
      * @param \Cake\Console\Arguments $args The command arguments.
      * @param \Cake\Console\ConsoleIo $io The console io
@@ -116,8 +116,8 @@ class HelpCommand extends Command implements CommandCollectionAwareInterface
         }
         $io->out('');
 
-        $io->out('To run a command, type <info>`cake shell_name [args|options]`</info>');
-        $io->out('To get help on a specific command, type <info>`cake shell_name --help`</info>', 2);
+        $io->out('To run a command, type <info>`cake command_name [args|options]`</info>');
+        $io->out('To get help on a specific command, type <info>`cake command_name --help`</info>', 2);
     }
 
     /**
@@ -153,7 +153,7 @@ class HelpCommand extends Command implements CommandCollectionAwareInterface
     protected function buildOptionParser(ConsoleOptionParser $parser)
     {
         $parser->setDescription(
-            'Get the list of available shells for this application.'
+            'Get the list of available commands for this application.'
         )->addOption('xml', [
             'help' => 'Get the listing as XML.',
             'boolean' => true

+ 1 - 1
src/Console/Arguments.php

@@ -117,7 +117,7 @@ class Arguments
     public function getArgument($name)
     {
         $offset = array_search($name, $this->argNames, true);
-        if ($offset === false) {
+        if ($offset === false || !isset($this->args[$offset])) {
             return null;
         }
 

+ 6 - 0
src/Console/ConsoleIo.php

@@ -566,6 +566,12 @@ class ConsoleIo
         }
 
         try {
+            // Create the directory using the current user permissions.
+            $directory = dirname($path);
+            if (!file_exists($directory)) {
+                mkdir($directory, 0777 ^ umask(), true);
+            }
+
             $file = new SplFileObject($path, 'w');
         } catch (RuntimeException $e) {
             $this->error("Could not write to `{$path}`. Permission denied.", 2);

+ 4 - 4
src/TestSuite/IntegrationTestTrait.php

@@ -196,11 +196,11 @@ trait IntegrationTestTrait
     /**
      * Auto-detect if the HTTP middleware stack should be used.
      *
+     * @before
      * @return void
      */
-    public function setUp()
+    public function setupServer()
     {
-        parent::setUp();
         $namespace = Configure::read('App.namespace');
         $this->_useHttpServer = class_exists($namespace . '\Application');
     }
@@ -208,11 +208,11 @@ trait IntegrationTestTrait
     /**
      * Clears the state used for requests.
      *
+     * @after
      * @return void
      */
-    public function tearDown()
+    public function cleanup()
     {
-        parent::tearDown();
         $this->_request = [];
         $this->_session = [];
         $this->_cookie = [];

+ 14 - 0
tests/TestCase/Console/ArgumentsTest.php

@@ -97,6 +97,20 @@ class ArgumentsTest extends TestCase
     }
 
     /**
+     * get arguments missing value
+     *
+     * @return void
+     */
+    public function testGetArgumentMissing()
+    {
+        $values = [];
+        $names = ['size', 'color'];
+        $args = new Arguments($values, [], $names);
+        $this->assertNull($args->getArgument('size'));
+        $this->assertNull($args->getArgument('color'));
+    }
+
+    /**
      * test getOptions()
      *
      * @return void

+ 19 - 0
tests/TestCase/Console/ConsoleIoTest.php

@@ -580,6 +580,8 @@ class ConsoleIoTest extends TestCase
      */
     public function testCreateFileSuccess()
     {
+        $this->err->expects($this->never())
+            ->method('write');
         $path = TMP . 'shell_test';
         mkdir($path);
 
@@ -592,6 +594,23 @@ class ConsoleIoTest extends TestCase
         $this->assertStringEqualsFile($file, $contents);
     }
 
+    public function testCreateFileDirectoryCreation()
+    {
+        $this->err->expects($this->never())
+            ->method('write');
+
+        $directory = TMP . 'shell_test';
+        $this->assertFileNotExists($directory, 'Directory should not exist before createFile');
+
+        $path = $directory . DS . 'create.txt';
+        $contents = 'some content';
+        $result = $this->io->createFile($path, $contents);
+
+        $this->assertTrue($result, 'File should create');
+        $this->assertFileExists($path);
+        $this->assertStringEqualsFile($path, $contents);
+    }
+
     /**
      * Test that createFile with permissions error.
      *