Browse Source

Merge pull request #15331 from mirko-pagliai/ServerRequest

`ServerRequest::is()`: `$args` is mixed
Mark Story 5 years ago
parent
commit
5d61d2c13c
2 changed files with 19 additions and 1 deletions
  1. 1 1
      src/Http/ServerRequest.php
  2. 18 0
      tests/TestCase/Http/ServerRequestTest.php

+ 1 - 1
src/Http/ServerRequest.php

@@ -801,7 +801,7 @@ class ServerRequest implements ArrayAccess, ServerRequestInterface
      *
      * @param string|string[] $type The type of request you want to check. If an array
      *   this method will return true if the request matches any type.
-     * @param array ...$args List of arguments
+     * @param mixed ...$args List of arguments
      * @return bool Whether or not the request is the type you are checking.
      */
     public function is($type, ...$args)

+ 18 - 0
tests/TestCase/Http/ServerRequestTest.php

@@ -1530,6 +1530,24 @@ class ServerRequestTest extends TestCase
         $request->clearDetectorCache();
         $this->assertFalse($request->isIndex());
 
+        ServerRequest::addDetector('withParams', function ($request, array $params) {
+            foreach ($params as $name => $value) {
+                if ($request->getParam($name) != $value) {
+                    return false;
+                }
+            }
+
+            return true;
+        });
+
+        $request = $request->withParam('controller', 'Pages')->withParam('action', 'index');
+        $request->clearDetectorCache();
+        $this->assertTrue($request->isWithParams(['controller' => 'Pages', 'action' => 'index']));
+
+        $request = $request->withParam('controller', 'Posts');
+        $request->clearDetectorCache();
+        $this->assertFalse($request->isWithParams(['controller' => 'Pages', 'action' => 'index']));
+
         ServerRequest::addDetector('callme', function ($request) {
             return $request->getAttribute('return');
         });