Browse Source

Merge branch 'master' into 3.next

Mark Story 7 years ago
parent
commit
80a7b39172

+ 4 - 4
appveyor.yml

@@ -33,7 +33,7 @@ init:
 
 install:
   - IF EXIST C:\php (SET PHP=0)
-  - ps: appveyor-retry cinst --params '""/InstallDir:C:\php""' --ignore-checksums -y php --version ((choco search php --exact --all-versions -r | select-string -pattern $env:php_ver_target | sort { [version]($_ -split '\|' | select -last 1) } -Descending | Select-Object -first 1) -replace '[php|]','')
+  - ps: appveyor-retry cinst --no-progress --params '""/InstallDir:C:\php""' --ignore-checksums -y php --version ((choco search php --exact --all-versions -r | select-string -pattern $env:php_ver_target | sort { [version]($_ -split '\|' | select -last 1) } -Descending | Select-Object -first 1) -replace '[php|]','')
   - cd C:\php
   - copy php.ini-production php.ini /Y
   - echo date.timezone="UTC" >> php.ini
@@ -44,14 +44,14 @@ install:
   - echo extension=php_fileinfo.dll >> php.ini
 
   - curl -fsS https://windows.php.net/downloads/pecl/releases/pdo_sqlsrv/5.2.0/php_pdo_sqlsrv-5.2.0-7.2-nts-vc15-x64.zip -o pdosqlsrv.zip
-  - 7z x pdosqlsrv.zip -oC:\php\ext php_pdo_sqlsrv.dll > nul
+  - 7z x pdosqlsrv.zip -oC:\php\ext php_pdo_sqlsrv.dll -aoa > nul
   - curl -fsS https://windows.php.net/downloads/pecl/releases/sqlsrv/5.2.0/php_sqlsrv-5.2.0-7.2-nts-vc15-x64.zip -o sqlsrv.zip
-  - 7z x sqlsrv.zip -oC:\php\ext php_sqlsrv.dll > nul
+  - 7z x sqlsrv.zip -oC:\php\ext php_sqlsrv.dll -aoa > nul
   - echo extension=php_pdo_sqlsrv.dll >> php.ini
   - echo extension=php_sqlsrv.dll >> php.ini
 
   - curl -fsS https://windows.php.net/downloads/pecl/releases/wincache/2.0.0.8/php_wincache-2.0.0.8-7.2-nts-vc15-x64.zip -o wincache.zip
-  - 7z x wincache.zip -oC:\php\ext php_wincache.dll > nul
+  - 7z x wincache.zip -oC:\php\ext php_wincache.dll -aoa > nul
   - echo extension=php_wincache.dll >> php.ini
   - echo wincache.enablecli = 1 >> php.ini
 

+ 1 - 0
phpstan.neon

@@ -27,6 +27,7 @@ parameters:
         - '#Call to an undefined method DOMNode::setAttribute\(\)#'
         - '#Binary operation "\+" between array|false and array results in an error#'
         - '#Result of method Cake\\Auth\\BaseAuthenticate::unauthenticated\(\) \(void\) is used#'
+        - '#Call to an undefined method DateTimeInterface::setTimezone\(\)#'
     earlyTerminatingMethodCalls:
         Cake\Console\Shell:
             - abort

+ 8 - 3
src/Cache/Cache.php

@@ -496,14 +496,19 @@ class Cache
      *
      * @param array $keys Array of cache keys to be deleted
      * @param string $config name of the configuration to use. Defaults to 'default'
-     * @return array of boolean values that are true if the value was successfully deleted, false if it didn't exist or
-     * couldn't be removed
+     * @return array of boolean values that are true if the value was successfully deleted,
+     * false if it didn't exist or couldn't be removed.
      */
     public static function deleteMany($keys, $config = 'default')
     {
         $backend = static::pool($config);
 
-        return $backend->deleteMultiple($keys);
+        $return = [];
+        foreach ($keys as $key) {
+            $return[$key] = $backend->delete($key);
+        }
+
+        return $return;
     }
 
     /**

+ 4 - 1
src/Cache/Engine/FileEngine.php

@@ -395,7 +395,10 @@ class FileEngine extends CacheEngine
         if (!$createKey && !$path->isFile()) {
             return false;
         }
-        if (empty($this->_File) || $this->_File->getBasename() !== $key) {
+        if (empty($this->_File) ||
+            $this->_File->getBasename() !== $key ||
+            $this->_File->valid() === false
+        ) {
             $exists = file_exists($path->getPathname());
             try {
                 $this->_File = $path->openFile('c+');

+ 3 - 3
src/Console/CommandCollection.php

@@ -162,7 +162,7 @@ class CommandCollection implements IteratorAggregate, Countable
      * the long name (`plugin.command`) will be returned.
      *
      * @param string $plugin The plugin to scan.
-     * @return array Discovered plugin commands.
+     * @return string[] Discovered plugin commands.
      */
     public function discoverPlugin($plugin)
     {
@@ -176,7 +176,7 @@ class CommandCollection implements IteratorAggregate, Countable
      * Resolve names based on existing commands
      *
      * @param array $input The results of a CommandScanner operation.
-     * @return array A flat map of command names => class names.
+     * @return string[] A flat map of command names => class names.
      */
     protected function resolveNames(array $input)
     {
@@ -213,7 +213,7 @@ class CommandCollection implements IteratorAggregate, Countable
      * Commands defined in the application will ovewrite commands with
      * the same name provided by CakePHP.
      *
-     * @return array An array of command names and their classes.
+     * @return string[] An array of command names and their classes.
      */
     public function autoDiscover()
     {

+ 18 - 1
src/Console/CommandRunner.php

@@ -162,7 +162,7 @@ class CommandRunner implements EventDispatcherInterface
             $result = $this->runShell($shell, $argv);
         }
         if ($shell instanceof Command) {
-            $result = $shell->run($argv, $io);
+            $result = $this->runCommand($shell, $argv, $io);
         }
 
         if ($result === null || $result === true) {
@@ -353,6 +353,23 @@ class CommandRunner implements EventDispatcherInterface
     }
 
     /**
+     * Execute a Command class.
+     *
+     * @param \Cake\Console\Command $command The command to run.
+     * @param array $argv The CLI arguments to invoke.
+     * @param \Cake\Console\ConsoleIo $io The console io
+     * @return int Exit code
+     */
+    protected function runCommand(Command $command, array $argv, ConsoleIo $io)
+    {
+        try {
+            return $command->run($argv, $io);
+        } catch (StopException $e) {
+            return $e->getCode();
+        }
+    }
+
+    /**
      * Execute a Shell class.
      *
      * @param \Cake\Console\Shell $shell The shell to run.

+ 1 - 1
src/Console/ConsoleOptionParser.php

@@ -1086,7 +1086,7 @@ class ConsoleOptionParser
      *
      * @param string $argument The argument to append
      * @param array $args The array of parsed args to append to.
-     * @return array Args
+     * @return string[] Args
      * @throws \Cake\Console\Exception\ConsoleException
      */
     protected function _parseArg($argument, $args)

+ 1 - 1
src/Core/Configure.php

@@ -264,7 +264,7 @@ class Configure
      * Use Configure::isConfigured() instead.
      *
      * @param string|null $name Engine name.
-     * @return array|bool Array of the configured Engine objects, bool for specific name.
+     * @return string[]|bool Array of the configured Engine objects, bool for specific name.
      */
     public static function configured($name = null)
     {

+ 1 - 1
src/Event/EventListenerInterface.php

@@ -38,7 +38,7 @@ interface EventListenerInterface
      *  }
      * ```
      *
-     * @return array associative array or event key names pointing to the function
+     * @return array Associative array or event key names pointing to the function
      * that should be called in the object when the respective event is fired
      */
     public function implementedEvents();

+ 9 - 9
src/Http/Response.php

@@ -24,6 +24,7 @@ use Cake\Http\CorsBuilder;
 use Cake\Http\Exception\NotFoundException;
 use Cake\Log\Log;
 use DateTime;
+use DateTimeInterface;
 use DateTimeZone;
 use InvalidArgumentException;
 use Psr\Http\Message\ResponseInterface;
@@ -1608,7 +1609,7 @@ class Response implements ResponseInterface
      * `$response->expires(new DateTime('+1 day'))` Will set the expiration in next 24 hours
      * `$response->expires()` Will return the current expiration header value
      *
-     * @param string|\DateTime|null $time Valid time string or \DateTime instance.
+     * @param string|\DateTimeInterface|null $time Valid time string or \DateTime instance.
      * @return string|null
      * @deprecated 3.4.0 Use withExpires() instead.
      */
@@ -1644,7 +1645,7 @@ class Response implements ResponseInterface
      * $response->withExpires(new DateTime('+1 day'))
      * ```
      *
-     * @param string|\DateTime $time Valid time string or \DateTime instance.
+     * @param string|\DateTimeInterface $time Valid time string or \DateTime instance.
      * @return static
      */
     public function withExpires($time)
@@ -1664,7 +1665,7 @@ class Response implements ResponseInterface
      * `$response->modified(new DateTime('+1 day'))` Will set the modification date in the past 24 hours
      * `$response->modified()` Will return the current Last-Modified header value
      *
-     * @param string|\DateTime|null $time Valid time string or \DateTime instance.
+     * @param string|\DateTimeInterface|null $time Valid time string or \DateTime instance.
      * @return string|null
      * @deprecated 3.4.0 Use withModified() instead.
      */
@@ -1700,7 +1701,7 @@ class Response implements ResponseInterface
      * $response->withModified(new DateTime('+1 day'))
      * ```
      *
-     * @param string|\DateTime $time Valid time string or \DateTime instance.
+     * @param string|\DateTimeInterface $time Valid time string or \DateTimeInterface instance.
      * @return static
      */
     public function withModified($time)
@@ -1885,21 +1886,20 @@ class Response implements ResponseInterface
      * Returns a DateTime object initialized at the $time param and using UTC
      * as timezone
      *
-     * @param string|int|\DateTime|null $time Valid time string or \DateTime instance.
-     * @return \DateTime
+     * @param string|int|\DateTimeInterface|null $time Valid time string or \DateTimeInterface instance.
+     * @return \DateTimeInterface
      */
     protected function _getUTCDate($time = null)
     {
-        if ($time instanceof DateTime) {
+        if ($time instanceof DateTimeInterface) {
             $result = clone $time;
         } elseif (is_int($time)) {
             $result = new DateTime(date('Y-m-d H:i:s', $time));
         } else {
             $result = new DateTime($time);
         }
-        $result->setTimezone(new DateTimeZone('UTC'));
 
-        return $result;
+        return $result->setTimezone(new DateTimeZone('UTC'));
     }
 
     /**

+ 2 - 2
src/I18n/FrozenTime.php

@@ -241,7 +241,7 @@ class FrozenTime extends Chronos implements JsonSerializable
     }
 
     /**
-     * Returns true this instance will happen within the specified interval
+     * Returns true this instance happened within the specified interval
      *
      * This overridden method provides backwards compatible behavior for integers,
      * or strings with trailing spaces. This behavior is *deprecated* and will be
@@ -266,7 +266,7 @@ class FrozenTime extends Chronos implements JsonSerializable
     }
 
     /**
-     * Returns true this instance happened within the specified interval
+     * Returns true this instance will happen within the specified interval
      *
      * This overridden method provides backwards compatible behavior for integers,
      * or strings with trailing spaces. This behavior is *deprecated* and will be

+ 19 - 2
src/View/View.php

@@ -1223,7 +1223,7 @@ class View implements EventDispatcherInterface
             'templatePath' => 'getTemplatePath',
             'template' => 'getTemplate',
             'layout' => 'getLayout',
-            'layoutPath' => 'setLayoutPath',
+            'layoutPath' => 'getLayoutPath',
             'autoLayout' => 'isAutoLayoutEnabled',
             'theme' => 'getTheme',
             'request' => 'getRequest',
@@ -1305,7 +1305,6 @@ class View implements EventDispatcherInterface
             'response' => 'setResponse',
             'subDir' => 'setSubDir',
             'plugin' => 'setPlugin',
-            'name' => 'setName',
             'elementCache' => 'setElementCache',
         ];
         if (isset($protected[$name])) {
@@ -1330,6 +1329,13 @@ class View implements EventDispatcherInterface
             return $this->helpers = $value;
         }
 
+        if ($name === 'name') {
+            deprecationWarning(
+                'View::$name is protected now. ' .
+                'You can use viewBuilder()->setName() to change the name a view uses before building it.'
+            );
+        }
+
         $this->{$name} = $value;
     }
 
@@ -1473,6 +1479,17 @@ class View implements EventDispatcherInterface
     }
 
     /**
+     * Returns the View's controller name.
+     *
+     * @return string|null
+     * @since 3.7.7
+     */
+    public function getName()
+    {
+        return $this->name;
+    }
+
+    /**
      * Returns the plugin name.
      *
      * @return string|null

+ 5 - 0
tests/TestCase/Console/ConsoleInputTest.php

@@ -41,6 +41,11 @@ class ConsoleInputTest extends TestCase
      */
     public function testDataAvailable()
     {
+        $this->skipIf(
+            DS === '\\',
+            'Skip ConsoleInput tests on Windows as they fail on AppVeyor.'
+        );
+
         $this->assertFalse($this->in->dataAvailable());
     }
 }

+ 4 - 0
tests/TestCase/Http/ResponseTest.php

@@ -1092,6 +1092,10 @@ class ResponseTest extends TestCase
         $new = $response->withModified($now);
         $this->assertEquals(gmdate($format) . ' GMT', $new->getHeaderLine('Last-Modified'));
 
+        $now = new \DateTimeImmutable();
+        $new = $response->withModified($now);
+        $this->assertEquals(gmdate($format) . ' GMT', $new->getHeaderLine('Last-Modified'));
+
         $time = new \DateTime('+1 day', new \DateTimeZone('UTC'));
         $new = $response->withModified('+1 day');
         $this->assertEquals($time->format($format) . ' GMT', $new->getHeaderLine('Last-Modified'));

+ 14 - 0
tests/TestCase/View/ViewTest.php

@@ -2152,6 +2152,20 @@ TEXT;
     }
 
     /**
+     * Test getName() and getPlugin().
+     *
+     * @return void
+     */
+    public function testGetNamePlugin()
+    {
+        $this->assertSame('Posts', $this->View->getName());
+        $this->assertNull($this->View->getPlugin());
+
+        $this->assertSame($this->View, $this->View->setPlugin('TestPlugin'));
+        $this->assertSame('TestPlugin', $this->View->getPlugin());
+    }
+
+    /**
      * Test testHasRendered property
      *
      * @return void

+ 3 - 0
tests/test_app/TestApp/Auth/TestAuthenticate.php

@@ -28,6 +28,9 @@ class TestAuthenticate extends BaseAuthenticate
 
     public $authenticationProvider;
 
+    /**
+     * @return array
+     */
     public function implementedEvents()
     {
         return [