Browse Source

Merge branch '3.next' into 4.x

ADmad 6 years ago
parent
commit
d7dedf0e60

+ 23 - 0
.github/workflows/stale.yml

@@ -0,0 +1,23 @@
+name: Mark stale issues and pull requests
+
+on:
+  schedule:
+  - cron: "0 0 * * *"
+
+jobs:
+  stale:
+
+    runs-on: ubuntu-latest
+    
+    steps:
+    - uses: actions/stale@v1
+      with:
+        repo-token: ${{ secrets.GITHUB_TOKEN }}
+        stale-issue-message: 'This issue is stale because it has been open for 120 days with no activity. Remove the `stale` label or comment or this will be closed in 15 days'
+        stale-pr-message: 'This pull request is stale because it has been open 30 days with no activity. Remove the `stale` label or comment on this issue, or it will be closed in 15 days'
+        stale-issue-label: 'stale'
+        stale-pr-label: 'stale'
+        days-before-stale: 120
+        days-before-close: 15
+        exempt-issue-label: 'pinned'
+        exempt-pr-label: 'pinned'

+ 0 - 1
phpunit.xml.dist

@@ -37,7 +37,6 @@
 
     <php>
         <ini name="memory_limit" value="-1"/>
-        <ini name="apc.enable_cli" value="1"/>
         <!-- E_ALL & ~E_USER_DEPRECATED (16383)-->
         <!-- E_ALL (32767) -->
         <ini name="error_reporting" value="32767"/>

+ 2 - 12
src/Cache/Engine/MemcachedEngine.php

@@ -279,7 +279,7 @@ class MemcachedEngine extends CacheEngine
      * Write data for key into cache. When using memcached as your cache engine
      * remember that the Memcached pecl extension does not support cache expiry
      * times greater than 30 days in the future. Any duration greater than 30 days
-     * will be treated as never expiring.
+     * will be treated as real Unix time value rather than an offset from current time.
      *
      * @param string $key Identifier for the data
      * @param mixed $value Data to be cached
@@ -287,14 +287,11 @@ class MemcachedEngine extends CacheEngine
      *   the driver supports TTL then the library may set a default value
      *   for it or let the driver take care of that.
      * @return bool True if the data was successfully cached, false on failure
-     * @see https://secure.php.net/manual/en/memcache.set.php
+     * @see https://www.php.net/manual/en/memcached.set.php
      */
     public function set($key, $value, $ttl = null): bool
     {
         $duration = $this->duration($ttl);
-        if ($duration > 30 * DAY) {
-            $duration = 0;
-        }
 
         return $this->_Memcached->set($this->_key($key), $value, $duration);
     }
@@ -315,9 +312,6 @@ class MemcachedEngine extends CacheEngine
             $cacheData[$this->_key($key)] = $value;
         }
         $duration = $this->duration($ttl);
-        if ($duration > 30 * DAY) {
-            $duration = 0;
-        }
 
         return (bool)$this->_Memcached->setMulti($cacheData, $duration);
     }
@@ -449,10 +443,6 @@ class MemcachedEngine extends CacheEngine
     public function add(string $key, $value): bool
     {
         $duration = $this->_config['duration'];
-        if ($duration > 30 * DAY) {
-            $duration = 0;
-        }
-
         $key = $this->_key($key);
 
         return $this->_Memcached->add($key, $value, $duration);

+ 2 - 3
src/Controller/Controller.php

@@ -589,9 +589,8 @@ class Controller implements EventListenerInterface, EventDispatcherInterface
     /**
      * Redirects to given $url, after turning off $this->autoRender.
      *
-     * @param string|array $url A string or array-based URL pointing to another location within the app,
-     *     or an absolute URL
-     * @param int $status HTTP status code (eg: 301)
+     * @param string|array|\Psr\Http\Message\UriInterface $url A string, array-based URL or UriInterface instance.
+     * @param int $status HTTP status code. Defaults to `302`.
      * @return \Cake\Http\Response|null
      * @link https://book.cakephp.org/3.0/en/controllers.html#Controller::redirect
      */

+ 2 - 5
src/Mailer/Message.php

@@ -674,10 +674,7 @@ class Message implements JsonSerializable, Serializable
     {
         if (!is_array($email)) {
             $this->validateEmail($email, $varName);
-            if ($name === null) {
-                $name = $email;
-            }
-            $this->{$varName} = [$email => $name];
+            $this->{$varName} = [$email => $name ?? $email];
 
             return $this;
         }
@@ -687,7 +684,7 @@ class Message implements JsonSerializable, Serializable
                 $key = $value;
             }
             $this->validateEmail($key, $varName);
-            $list[$key] = $value;
+            $list[$key] = $value ?? $key;
         }
         $this->{$varName} = $list;
 

+ 4 - 2
src/Routing/Router.php

@@ -455,10 +455,10 @@ class Router
      * - `_name` - Name of route. If you have setup named routes you can use this key
      *   to specify it.
      *
-     * @param string|array|null $url An array specifying any of the following:
+     * @param string|array|\Psr\Http\Message\UriInterface|null $url An array specifying any of the following:
      *   'controller', 'action', 'plugin' additionally, you can provide routed
      *   elements or query string parameters. If string it can be name any valid url
-     *   string.
+     *   string or it can be an UriInterface instance.
      * @param bool $full If true, the full base URL will be prepended to the result.
      *   Default is false.
      * @return string Full translated URL with base path.
@@ -539,6 +539,8 @@ class Router
 
             $output = static::$_collection->match($url, $context);
         } else {
+            $url = (string)$url;
+
             $plainString = (
                 strpos($url, 'javascript:') === 0 ||
                 strpos($url, 'mailto:') === 0 ||

+ 3 - 1
src/TestSuite/Constraint/Email/MailSentWith.php

@@ -55,7 +55,9 @@ class MailSentWith extends MailConstraintBase
         $emails = $this->getMessages();
         foreach ($emails as $email) {
             $value = $email->{'get' . ucfirst($this->method)}();
-            if (in_array($this->method, ['to', 'cc', 'bcc', 'from'], true) && isset($value[$other])) {
+            if (in_array($this->method, ['to', 'cc', 'bcc', 'from'], true)
+                && array_key_exists($other, $value)
+            ) {
                 return true;
             }
             if ($value === $other) {

+ 14 - 0
tests/TestCase/Controller/ControllerTest.php

@@ -29,6 +29,7 @@ use PHPUnit\Framework\Error\Warning;
 use TestApp\Controller\Admin\PostsController;
 use TestApp\Controller\TestController;
 use TestPlugin\Controller\TestPluginController;
+use Zend\Diactoros\Uri;
 
 /**
  * ControllerTest class
@@ -302,6 +303,19 @@ class ControllerTest extends TestCase
         $this->assertInstanceOf('Cake\Http\Response', $result);
     }
 
+    public function testControllerRedirect()
+    {
+        $Controller = new Controller();
+        $uri = new Uri('/foo/bar');
+        $response = $Controller->redirect($uri);
+        $this->assertEquals('http://localhost/foo/bar', $response->getHeaderLine('Location'));
+
+        $Controller = new Controller();
+        $uri = new Uri('http://cakephp.org/foo/bar');
+        $response = $Controller->redirect($uri);
+        $this->assertEquals('http://cakephp.org/foo/bar', $response->getHeaderLine('Location'));
+    }
+
     /**
      * Generates status codes for redirect test.
      *

+ 6 - 1
tests/TestCase/TestSuite/EmailTraitTest.php

@@ -109,13 +109,14 @@ class EmailTraitTest extends TestCase
 
         $this->sendEmails();
 
-        $this->assertMailCount(2);
+        $this->assertMailCount(3);
 
         $this->assertMailSentFromAt(0, 'default@example.com');
         $this->assertMailSentFromAt(1, 'alternate@example.com');
 
         $this->assertMailSentToAt(0, 'to@example.com');
         $this->assertMailSentToAt(1, 'to2@example.com');
+        $this->assertMailSentToAt(2, 'to3@example.com');
 
         $this->assertMailContainsAt(0, 'text');
         $this->assertMailContainsAt(1, 'html');
@@ -243,5 +244,9 @@ class EmailTraitTest extends TestCase
             ->setCc('cc2@example.com')
             ->setEmailFormat(Message::MESSAGE_HTML)
             ->deliver('html');
+
+        (new Mailer('alternate'))
+            ->setTo(['to3@example.com' => null])
+            ->deliver('html');
     }
 }