浏览代码

Merge branch 'master' into 3.next

Mark Story 9 年之前
父节点
当前提交
585453bdd0

+ 5 - 5
src/Console/ConsoleIo.php

@@ -128,7 +128,7 @@ class ConsoleIo
      *
      * @param string|array $message A string or an array of strings to output
      * @param int $newlines Number of newlines to append
-     * @return int|bool Returns the number of bytes returned from writing to stdout.
+     * @return int|bool The number of bytes returned from writing to stdout.
      */
     public function verbose($message, $newlines = 1)
     {
@@ -140,7 +140,7 @@ class ConsoleIo
      *
      * @param string|array $message A string or an array of strings to output
      * @param int $newlines Number of newlines to append
-     * @return int|bool Returns the number of bytes returned from writing to stdout.
+     * @return int|bool The number of bytes returned from writing to stdout.
      */
     public function quiet($message, $newlines = 1)
     {
@@ -161,7 +161,7 @@ class ConsoleIo
      * @param string|array $message A string or an array of strings to output
      * @param int $newlines Number of newlines to append
      * @param int $level The message's output level, see above.
-     * @return int|bool Returns the number of bytes returned from writing to stdout.
+     * @return int|bool The number of bytes returned from writing to stdout.
      */
     public function out($message = '', $newlines = 1, $level = ConsoleIo::NORMAL)
     {
@@ -213,11 +213,11 @@ class ConsoleIo
      *
      * @param string|array $message A string or an array of strings to output
      * @param int $newlines Number of newlines to append
-     * @return void
+     * @return int|bool The number of bytes returned from writing to stderr.
      */
     public function err($message = '', $newlines = 1)
     {
-        $this->_err->write($message, $newlines);
+        return $this->_err->write($message, $newlines);
     }
 
     /**

+ 3 - 3
src/Console/ConsoleOutput.php

@@ -170,12 +170,12 @@ class ConsoleOutput
     }
 
     /**
-     * Outputs a single or multiple messages to stdout. If no parameters
+     * Outputs a single or multiple messages to stdout or stderr. If no parameters
      * are passed, outputs just a newline.
      *
      * @param string|array $message A string or an array of strings to output
      * @param int $newlines Number of newlines to append
-     * @return int Returns the number of bytes returned from writing to stdout.
+     * @return int|bool The number of bytes returned from writing to output.
      */
     public function write($message, $newlines = 1)
     {
@@ -244,7 +244,7 @@ class ConsoleOutput
      * Writes a message to the output stream.
      *
      * @param string $message Message to write.
-     * @return bool success
+     * @return int|bool The number of bytes returned from writing to output.
      */
     protected function _write($message)
     {

+ 10 - 10
src/Console/Shell.php

@@ -407,7 +407,7 @@ class Shell
      * to be dispatched.
      * Built-in extra parameter is :
      * - `requested` : if used, will prevent the Shell welcome message to be displayed
-     * @return mixed
+     * @return int|bool|null
      * @link http://book.cakephp.org/3.0/en/console-and-shells.html#the-cakephp-console
      */
     public function runCommand($argv, $autoMethod = false, $extra = [])
@@ -417,7 +417,7 @@ class Shell
         try {
             list($this->params, $this->args) = $this->OptionParser->parse($argv);
         } catch (ConsoleException $e) {
-            $this->err('<error>Error: ' . $e->getMessage() . '</error>');
+            $this->err('Error: ' . $e->getMessage());
             $this->out($this->OptionParser->help($command));
 
             return false;
@@ -496,7 +496,7 @@ class Shell
      * Display the help in the correct format
      *
      * @param string $command The command to get help for.
-     * @return int|bool
+     * @return int|bool The number of bytes returned from writing to stdout.
      */
     protected function _displayHelp($command)
     {
@@ -609,7 +609,7 @@ class Shell
      *
      * @param string|array $message A string or an array of strings to output
      * @param int $newlines Number of newlines to append
-     * @return int|bool Returns the number of bytes returned from writing to stdout.
+     * @return int|bool The number of bytes returned from writing to stdout.
      */
     public function verbose($message, $newlines = 1)
     {
@@ -621,7 +621,7 @@ class Shell
      *
      * @param string|array $message A string or an array of strings to output
      * @param int $newlines Number of newlines to append
-     * @return int|bool Returns the number of bytes returned from writing to stdout.
+     * @return int|bool The number of bytes returned from writing to stdout.
      */
     public function quiet($message, $newlines = 1)
     {
@@ -642,7 +642,7 @@ class Shell
      * @param string|array|null $message A string or an array of strings to output
      * @param int $newlines Number of newlines to append
      * @param int $level The message's output level, see above.
-     * @return int|bool Returns the number of bytes returned from writing to stdout.
+     * @return int|bool The number of bytes returned from writing to stdout.
      * @link http://book.cakephp.org/3.0/en/console-and-shells.html#Shell::out
      */
     public function out($message = null, $newlines = 1, $level = Shell::NORMAL)
@@ -656,7 +656,7 @@ class Shell
      *
      * @param string|array|null $message A string or an array of strings to output
      * @param int $newlines Number of newlines to append
-     * @return int|bool Returns the number of bytes returned from writing to stderr.
+     * @return int|bool The number of bytes returned from writing to stderr.
      */
     public function err($message = null, $newlines = 1)
     {
@@ -669,7 +669,7 @@ class Shell
      * @param string|array|null $message A string or an array of strings to output
      * @param int $newlines Number of newlines to append
      * @param int $level The message's output level, see above.
-     * @return int|bool Returns the number of bytes returned from writing to stdout.
+     * @return int|bool The number of bytes returned from writing to stdout.
      * @see http://book.cakephp.org/3.0/en/console-and-shells.html#Shell::out
      */
     public function info($message = null, $newlines = 1, $level = Shell::NORMAL)
@@ -682,7 +682,7 @@ class Shell
      *
      * @param string|array|null $message A string or an array of strings to output
      * @param int $newlines Number of newlines to append
-     * @return int|bool Returns the number of bytes returned from writing to stderr.
+     * @return int|bool The number of bytes returned from writing to stderr.
      * @see http://book.cakephp.org/3.0/en/console-and-shells.html#Shell::err
      */
     public function warn($message = null, $newlines = 1)
@@ -696,7 +696,7 @@ class Shell
      * @param string|array|null $message A string or an array of strings to output
      * @param int $newlines Number of newlines to append
      * @param int $level The message's output level, see above.
-     * @return int|bool Returns the number of bytes returned from writing to stdout.
+     * @return int|bool The number of bytes returned from writing to stdout.
      * @see http://book.cakephp.org/3.0/en/console-and-shells.html#Shell::out
      */
     public function success($message = null, $newlines = 1, $level = Shell::NORMAL)

+ 1 - 0
src/Controller/Component/AuthComponent.php

@@ -282,6 +282,7 @@ class AuthComponent extends Component
             return null;
         }
 
+        /* @var \Cake\Controller\Controller $controller */
         $controller = $event->subject();
 
         $action = strtolower($controller->request->params['action']);

+ 2 - 1
src/Controller/Component/CsrfComponent.php

@@ -81,6 +81,7 @@ class CsrfComponent extends Component
         $response = $controller->response;
         $cookieName = $this->_config['cookieName'];
 
+        /* @var \Cake\Network\Request $request */
         $cookieData = $request->cookie($cookieName);
         if ($cookieData) {
             $request->params['_csrfToken'] = $cookieData;
@@ -150,7 +151,7 @@ class CsrfComponent extends Component
         $post = $request->data($this->_config['field']);
         $header = $request->header('X-CSRF-Token');
 
-        if (empty($cookie)) {
+        if (!$cookie) {
             throw new InvalidCsrfTokenException(__d('cake', 'Missing CSRF token cookie'));
         }
 

+ 1 - 0
src/Controller/Component/PaginatorComponent.php

@@ -179,6 +179,7 @@ class PaginatorComponent extends Component
         $options['page'] = (int)$options['page'] < 1 ? 1 : (int)$options['page'];
         list($finder, $options) = $this->_extractFinder($options);
 
+        /* @var \Cake\Datasource\RepositoryInterface $object */
         if (empty($query)) {
             $query = $object->find($finder, $options);
         } else {

+ 3 - 3
src/Database/Expression/TupleComparison.php

@@ -154,13 +154,13 @@ class TupleComparison extends Comparison
             return;
         }
 
-        foreach ($value as $i => $value) {
+        foreach ($value as $i => $val) {
             if ($this->isMulti()) {
-                foreach ($value as $v) {
+                foreach ($val as $v) {
                     $this->_traverseValue($v, $callable);
                 }
             } else {
-                $this->_traverseValue($value, $callable);
+                $this->_traverseValue($val, $callable);
             }
         }
     }

+ 4 - 3
src/Database/Expression/ValuesExpression.php

@@ -52,9 +52,9 @@ class ValuesExpression implements ExpressionInterface
     /**
      * The Query object to use as a values expression
      *
-     * @var \Cake\Database\Query
+     * @var \Cake\Database\Query|null
      */
-    protected $_query = false;
+    protected $_query = null;
 
     /**
      * Whether or not values have been casted to expressions
@@ -169,7 +169,7 @@ class ValuesExpression implements ExpressionInterface
      * the currently stored query
      *
      * @param \Cake\Database\Query|null $query The query to set/get
-     * @return \Cake\Database\Query
+     * @return \Cake\Database\Query|null
      */
     public function query(Query $query = null)
     {
@@ -296,6 +296,7 @@ class ValuesExpression implements ExpressionInterface
 
         foreach ($this->_values as $row => $values) {
             foreach ($types as $col => $type) {
+                /* @var \Cake\Database\Type\ExpressionTypeInterface $type */
                 $this->_values[$row][$col] = $type->toExpression($values[$col]);
             }
         }

+ 20 - 0
src/Network/Response.php

@@ -1843,4 +1843,24 @@ class Response implements ResponseInterface
     {
         exit($status);
     }
+
+    /**
+     * Returns an array that can be used to describe the internal state of this
+     * object.
+     *
+     * @return array
+     */
+    public function __debugInfo()
+    {
+        return [
+            'status' => $this->_status,
+            'contentType' => $this->_contentType,
+            'headers' => $this->headers,
+            'file' => $this->_file,
+            'fileRange' => $this->_fileRange,
+            'cookies' => $this->_cookies,
+            'cacheDirectives' => $this->_cacheDirectives,
+            'body' => $this->getBody()->getContents(),
+        ];
+    }
 }

+ 1 - 1
src/Shell/RoutesShell.php

@@ -69,7 +69,7 @@ class RoutesShell extends Shell
             $this->helper('table')->output($output);
             $this->out();
         } catch (MissingRouteException $e) {
-            $this->err("<warning>'$url' did not match any routes.</warning>");
+            $this->warn("'$url' did not match any routes.");
             $this->out();
 
             return false;

+ 1 - 1
src/Shell/Task/ExtractTask.php

@@ -140,7 +140,7 @@ class ExtractTask extends Shell
                 return;
             }
             if (strtoupper($response) === 'D') {
-                $this->err('<warning>No directories selected.</warning> Please choose a directory.');
+                $this->warn('No directories selected. Please choose a directory.');
             } elseif (is_dir($response)) {
                 $this->_paths[] = $response;
                 $defaultPath = 'D';

+ 2 - 2
src/Shell/Task/LoadTask.php

@@ -41,8 +41,8 @@ class LoadTask extends Shell
         $this->bootstrap = ROOT . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'bootstrap.php';
 
         if (empty($plugin)) {
-            $this->err('<error>You must provide a plugin name in CamelCase format.</error>');
-            $this->err('To load an "Example" plugin, run <info>`cake plugin load Example`</info>.');
+            $this->err('You must provide a plugin name in CamelCase format.');
+            $this->err('To load an "Example" plugin, run `cake plugin load Example`.');
 
             return false;
         }

+ 2 - 2
src/Shell/Task/UnloadTask.php

@@ -41,8 +41,8 @@ class UnloadTask extends Shell
         $this->bootstrap = ROOT . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'bootstrap.php';
 
         if (empty($plugin)) {
-            $this->err('<error>You must provide a plugin name in CamelCase format.</error>');
-            $this->err('To unload an "Example" plugin, run <info>`cake plugin unload Example`</info>.');
+            $this->err('You must provide a plugin name in CamelCase format.');
+            $this->err('To unload an "Example" plugin, run `cake plugin unload Example`.');
 
             return false;
         }

+ 6 - 6
src/Utility/Xml.php

@@ -203,8 +203,8 @@ class Xml
      */
     public static function fromArray($input, $options = [])
     {
-        if (method_exists($input, 'toArray')) {
-            $input = $input->toArray();
+        if (is_object($input) && method_exists($input, 'toArray') && is_callable([$input, 'toArray'])) {
+            $input = call_user_func([$input, 'toArray']);
         }
         if (!is_array($input) || count($input) !== 1) {
             throw new XmlException('Invalid input.');
@@ -257,8 +257,8 @@ class Xml
         }
         foreach ($data as $key => $value) {
             if (is_string($key)) {
-                if (method_exists($value, 'toArray')) {
-                    $value = $value->toArray();
+                if (is_object($value) && method_exists($value, 'toArray') && is_callable([$value, 'toArray'])) {
+                    $value = call_user_func([$value, 'toArray']);
                 }
 
                 if (!is_array($value)) {
@@ -323,8 +323,8 @@ class Xml
     {
         extract($data);
         $childNS = $childValue = null;
-        if (method_exists($value, 'toArray')) {
-            $value = $value->toArray();
+        if (is_object($value) && method_exists($value, 'toArray') && is_callable([$value, 'toArray'])) {
+            $value = call_user_func([$value, 'toArray']);
         }
         if (is_array($value)) {
             if (isset($value['@'])) {

+ 30 - 0
tests/TestCase/Console/ShellTest.php

@@ -1174,6 +1174,36 @@ TEXT;
     }
 
     /**
+     * test run command missing parameters
+     *
+     * @return void
+     */
+    public function testRunCommandMainMissingArgument()
+    {
+        $io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock();
+        $shell = $this->getMockBuilder('Cake\Console\Shell')
+            ->setMethods(['main', 'startup', 'getOptionParser'])
+            ->setConstructorArgs([$io])
+            ->getMock();
+
+        $parser = new ConsoleOptionParser('test');
+        $parser->addArgument('filename', [
+            'required' => true,
+            'help' => 'a file',
+        ]);
+        $shell->expects($this->once())
+            ->method('getOptionParser')
+            ->will($this->returnValue($parser));
+        $shell->expects($this->never())->method('main');
+
+        $io->expects($this->once())
+            ->method('err')
+            ->with('<error>Error: Missing required arguments. filename is required.</error>');
+        $result = $shell->runCommand([]);
+        $this->assertFalse($result, 'Shell should fail');
+    }
+
+    /**
      * test wrapBlock wrapping text.
      *
      * @return void

+ 23 - 0
tests/TestCase/Network/ResponseTest.php

@@ -2350,4 +2350,27 @@ class ResponseTest extends TestCase
         $this->assertFalse($response->hasHeader('Accept'));
         $this->assertFalse($response->hasHeader('accept'));
     }
+
+    /**
+     * Tests __debugInfo
+     *
+     * @return void
+     */
+    public function testDebugInfo()
+    {
+        $response = new Response();
+        $result = $response->__debugInfo();
+
+        $expected = [
+            'status' => 200,
+            'contentType' => 'text/html',
+            'headers' => [],
+            'file' => null,
+            'fileRange' => [],
+            'cookies' => [],
+            'cacheDirectives' => [],
+            'body' => null
+        ];
+        $this->assertEquals($expected, $result);
+    }
 }

+ 12 - 14
tests/TestCase/ORM/Behavior/TimestampBehaviorTest.php

@@ -221,9 +221,9 @@ class TimestampBehaviorTest extends TestCase
     public function testGetTimestamp()
     {
         $table = $this->getMockBuilder('Cake\ORM\Table')->getMock();
-        $this->Behavior = new TimestampBehavior($table);
+        $behavior = new TimestampBehavior($table);
 
-        $return = $this->Behavior->timestamp();
+        $return = $behavior->timestamp();
         $this->assertInstanceOf(
             'DateTime',
             $return,
@@ -232,22 +232,20 @@ class TimestampBehaviorTest extends TestCase
 
         $now = Time::now();
         $this->assertEquals($now, $return);
-
-        return $this->Behavior;
     }
 
     /**
      * testGetTimestampPersists
      *
-     * @depends testGetTimestamp
      * @return void
      */
-    public function testGetTimestampPersists($behavior)
+    public function testGetTimestampPersists()
     {
-        $this->Behavior = $behavior;
+        $table = $this->getMockBuilder('Cake\ORM\Table')->getMock();
+        $behavior = new TimestampBehavior($table);
 
-        $initialValue = $this->Behavior->timestamp();
-        $postValue = $this->Behavior->timestamp();
+        $initialValue = $behavior->timestamp();
+        $postValue = $behavior->timestamp();
 
         $this->assertSame(
             $initialValue,
@@ -259,15 +257,15 @@ class TimestampBehaviorTest extends TestCase
     /**
      * testGetTimestampRefreshes
      *
-     * @depends testGetTimestamp
      * @return void
      */
-    public function testGetTimestampRefreshes($behavior)
+    public function testGetTimestampRefreshes()
     {
-        $this->Behavior = $behavior;
+        $table = $this->getMockBuilder('Cake\ORM\Table')->getMock();
+        $behavior = new TimestampBehavior($table);
 
-        $initialValue = $this->Behavior->timestamp();
-        $postValue = $this->Behavior->timestamp(null, true);
+        $initialValue = $behavior->timestamp();
+        $postValue = $behavior->timestamp(null, true);
 
         $this->assertNotSame(
             $initialValue,

+ 30 - 0
tests/TestCase/Utility/XmlTest.php

@@ -1179,4 +1179,34 @@ XML;
 XML;
         $result = Xml::build($xml);
     }
+
+    /**
+     * Test building Xml with valid class-name in value.
+     *
+     * @see https://github.com/cakephp/cakephp/pull/9754
+     * @return void
+     */
+    public function testClassnameInValueRegressionTest()
+    {
+        $classname = self::class; // Will always be a valid class name
+        $data = [
+            'outer' => [
+                'inner' => $classname
+            ]
+        ];
+        $obj = Xml::build($data);
+        $result = $obj->asXml();
+        $this->assertContains('<inner>' . $classname . '</inner>', $result);
+    }
+
+    /**
+     * Needed function for testClassnameInValueRegressionTest.
+     *
+     * @ignore
+     * @return array
+     */
+    public function toArray()
+    {
+        return [];
+    }
 }