Browse Source

Merge branch 'master' into 3.next

ADmad 8 years ago
parent
commit
fdfd0260cb

+ 1 - 1
VERSION.txt

@@ -16,4 +16,4 @@
 // @license       https://opensource.org/licenses/mit-license.php MIT License
 // +--------------------------------------------------------------------------------------------+ //
 ////////////////////////////////////////////////////////////////////////////////////////////////////
-3.5.11
+3.5.12

+ 1 - 0
phpstan.neon

@@ -27,6 +27,7 @@ parameters:
         - '#Call to an undefined method object::toArray\(\)#'
         - '#Call to an undefined method object::__debugInfo\(\)#'
         - '#Call to an undefined static method Cake\\ORM\\TableRegistry::getConfig\(\)#'
+        - '#Method PDO::lastInsertId\(\) invoked with 2 parameters, 0-1 required#'
     earlyTerminatingMethodCalls:
         Cake\Shell\Shell:
             - abort

+ 5 - 1
src/Core/ObjectRegistry.php

@@ -278,7 +278,11 @@ abstract class ObjectRegistry implements Countable, IteratorAggregate
                 $objectName = $i;
             }
             list(, $name) = pluginSplit($objectName);
-            $normal[$name] = ['class' => $objectName, 'config' => $config];
+            if (isset($config['class'])) {
+                $normal[$name] = $config;
+            } else {
+                $normal[$name] = ['class' => $objectName, 'config' => $config];
+            }
         }
 
         return $normal;

+ 1 - 1
src/Database/Driver.php

@@ -21,7 +21,7 @@ use PDO;
  * Represents a database driver containing all specificities for
  * a database engine including its SQL dialect.
  *
- * @property \Cake\Datasource\ConnectionInterface|null $_connection
+ * @property \PDO|null $_connection
  */
 abstract class Driver
 {

+ 0 - 1
src/Datasource/ConnectionInterface.php

@@ -26,7 +26,6 @@ namespace Cake\Datasource;
  * @method \Cake\Database\StatementInterface prepare($sql)
  * @method \Cake\Database\StatementInterface execute($query, $params = [], array $types = [])
  * @method string quote($value, $type = null)
- * @method string|int lastInsertId($table = null, $column = null)
  */
 interface ConnectionInterface
 {

+ 32 - 20
src/Shell/ServerShell.php

@@ -43,33 +43,28 @@ class ServerShell extends Shell
      *
      * @var string
      */
-    protected $_host;
+    protected $_host = self::DEFAULT_HOST;
 
     /**
      * listen port
      *
      * @var int
      */
-    protected $_port;
+    protected $_port = self::DEFAULT_PORT;
 
     /**
      * document root
      *
      * @var string
      */
-    protected $_documentRoot;
+    protected $_documentRoot = WWW_ROOT;
 
     /**
-     * Override initialize of the Shell
+     * ini path
      *
-     * @return void
+     * @var string
      */
-    public function initialize()
-    {
-        $this->_host = self::DEFAULT_HOST;
-        $this->_port = self::DEFAULT_PORT;
-        $this->_documentRoot = WWW_ROOT;
-    }
+    protected $_iniPath = '';
 
     /**
      * Starts up the Shell and displays the welcome message.
@@ -83,14 +78,17 @@ class ServerShell extends Shell
      */
     public function startup()
     {
-        if (!empty($this->params['host'])) {
-            $this->_host = $this->params['host'];
+        if ($this->param('host')) {
+            $this->_host = $this->param('host');
+        }
+        if ($this->param('port')) {
+            $this->_port = $this->param('port');
         }
-        if (!empty($this->params['port'])) {
-            $this->_port = $this->params['port'];
+        if ($this->param('document_root')) {
+            $this->_documentRoot = $this->param('document_root');
         }
-        if (!empty($this->params['document_root'])) {
-            $this->_documentRoot = $this->params['document_root'];
+        if ($this->param('ini_path')) {
+            $this->_iniPath = $this->param('ini_path');
         }
 
         // For Windows
@@ -101,6 +99,11 @@ class ServerShell extends Shell
             $this->_documentRoot = $m[1] . '\\' . $m[2];
         }
 
+        $this->_iniPath = rtrim($this->_iniPath, DIRECTORY_SEPARATOR);
+        if (preg_match("/^([a-z]:)[\\\]+(.+)$/i", $this->_iniPath, $m)) {
+            $this->_iniPath = $m[1] . '\\' . $m[2];
+        }
+
         parent::startup();
     }
 
@@ -117,6 +120,7 @@ class ServerShell extends Shell
         $this->out(sprintf('App : %s', APP_DIR));
         $this->out(sprintf('Path: %s', APP));
         $this->out(sprintf('DocumentRoot: %s', $this->_documentRoot));
+        $this->out(sprintf('Ini Path: %s', $this->_iniPath));
         $this->hr();
     }
 
@@ -128,13 +132,18 @@ class ServerShell extends Shell
     public function main()
     {
         $command = sprintf(
-            'php -S %s:%d -t %s %s',
+            'php -S %s:%d -t %s',
             $this->_host,
             $this->_port,
-            escapeshellarg($this->_documentRoot),
-            escapeshellarg($this->_documentRoot . '/index.php')
+            escapeshellarg($this->_documentRoot)
         );
 
+        if (!empty($this->_iniPath)) {
+            $command = sprintf('%s -c %s', $command, $this->_iniPath);
+        }
+
+        $command = sprintf('%s %s', $command, escapeshellarg($this->_documentRoot . '/index.php'));
+
         $port = ':' . $this->_port;
         $this->out(sprintf('built-in server is running in http://%s%s/', $this->_host, $port));
         $this->out(sprintf('You can exit with <info>`CTRL-C`</info>'));
@@ -159,6 +168,9 @@ class ServerShell extends Shell
         ])->addOption('port', [
             'short' => 'p',
             'help' => 'ListenPort'
+        ])->addOption('ini_path', [
+            'short' => 'I',
+            'help' => 'php.ini path'
         ])->addOption('document_root', [
             'short' => 'd',
             'help' => 'DocumentRoot'

+ 3 - 0
src/View/Helper/FormHelper.php

@@ -2449,6 +2449,9 @@ class FormHelper extends Helper
             if (isset($options['empty'][$type])) {
                 $options[$type]['empty'] = $options['empty'][$type];
             }
+            if (isset($options['required']) && is_array($options[$type])) {
+                $options[$type]['required'] = $options['required'];
+            }
         }
 
         $hasYear = is_array($options['year']);

+ 1 - 0
tests/TestCase/Shell/ServerShellTest.php

@@ -46,6 +46,7 @@ class ServerShellTest extends TestCase
         $options = $parser->options();
         $this->assertArrayHasKey('host', $options);
         $this->assertArrayHasKey('port', $options);
+        $this->assertArrayHasKey('ini_path', $options);
         $this->assertArrayHasKey('document_root', $options);
     }
 }

+ 17 - 0
tests/TestCase/View/Helper/FormHelperTest.php

@@ -7018,6 +7018,23 @@ class FormHelperTest extends TestCase
     }
 
     /**
+     * test control() datetime & required attributes
+     *
+     * @return void
+     */
+    public function testControlDatetimeRequired()
+    {
+        $result = $this->Form->control('birthday', [
+            'type' => 'date',
+            'required' => true
+        ]);
+        $this->assertContains(
+            '<select name="birthday[year]" required="required"',
+            $result
+        );
+    }
+
+    /**
      * testYearAutoExpandRange method
      *
      * @return void

+ 77 - 0
tests/TestCase/View/HelperRegistryTest.php

@@ -351,4 +351,81 @@ class HelperRegistryTest extends TestCase
         $this->Helpers->load('Html', ['key' => 'value']);
         $this->Helpers->load('Html', ['key' => 'new value']);
     }
+
+    /**
+     * Test ObjectRegistry normalizeArray
+     *
+     * @return void
+     */
+    public function testArrayIsNormalized()
+    {
+        $config = [
+            'SomeHelper' => [
+                'value' => 1,
+                'value2' => 2
+            ],
+            'Plugin.SomeOtherHelper' => [
+                'value' => 1,
+                'value2' => 2
+            ]
+        ];
+        $result = $this->Helpers->normalizeArray($config);
+        $expected = [
+            'SomeHelper' => [
+                'class' => 'SomeHelper',
+                'config' => [
+                    'value' => 1,
+                    'value2' => 2
+                ]
+            ],
+            'SomeOtherHelper' => [
+                'class' => 'Plugin.SomeOtherHelper',
+                'config' => [
+                    'value' => 1,
+                    'value2' => 2
+                ]
+            ],
+        ];
+        $this->assertEquals($expected, $result);
+    }
+
+    /**
+     * Test that calling normalizeArray multiple times does
+     * not nest the configuration.
+     *
+     * @return void
+     */
+    public function testArrayIsNormalizedAfterMultipleCalls()
+    {
+        $config = [
+            'SomeHelper' => [
+                'value' => 1,
+                'value2' => 2
+            ],
+            'Plugin.SomeOtherHelper' => [
+                'value' => 1,
+                'value2' => 2
+            ]
+        ];
+
+        $result1 = $this->Helpers->normalizeArray($config);
+        $result2 = $this->Helpers->normalizeArray($result1);
+        $expected = [
+            'SomeHelper' => [
+                'class' => 'SomeHelper',
+                'config' => [
+                    'value' => 1,
+                    'value2' => 2
+                ]
+            ],
+            'SomeOtherHelper' => [
+                'class' => 'Plugin.SomeOtherHelper',
+                'config' => [
+                    'value' => 1,
+                    'value2' => 2
+                ]
+            ],
+        ];
+        $this->assertEquals($expected, $result2);
+    }
 }