Browse Source

Add test for spread operator as well.

Mark Story 5 years ago
parent
commit
19daf25103

+ 24 - 1
tests/TestCase/Controller/ControllerFactoryTest.php

@@ -591,7 +591,6 @@ class ControllerFactoryTest extends TestCase
      */
     public function testInvokeInjectPassedParametersVariadic()
     {
-        $this->container->add(stdClass::class, json_decode('{"key":"value"}'));
         $request = new ServerRequest([
             'url' => 'test_plugin_three/dependencies/optionalDep',
             'params' => [
@@ -608,4 +607,28 @@ class ControllerFactoryTest extends TestCase
         $this->assertNotNull($data);
         $this->assertSame(['one', 'two'], $data->args);
     }
+
+    /**
+     * Test that routing parameters are passed into controller action using spread operator
+     *
+     * @return void
+     */
+    public function testInvokeInjectPassedParametersSpread()
+    {
+        $request = new ServerRequest([
+            'url' => 'test_plugin_three/dependencies/optionalDep',
+            'params' => [
+                'plugin' => null,
+                'controller' => 'Dependencies',
+                'action' => 'spread',
+                'pass' => ['one', 'two'],
+            ],
+        ]);
+        $controller = $this->factory->create($request);
+        $result = $this->factory->invoke($controller);
+        $data = json_decode((string)$result->getBody());
+
+        $this->assertNotNull($data);
+        $this->assertSame(['one', 'two'], $data->args);
+    }
 }

+ 5 - 0
tests/test_app/TestApp/Controller/DependenciesController.php

@@ -41,4 +41,9 @@ class DependenciesController extends Controller
     {
         return $this->response->withStringBody(json_encode(['args' => func_get_args()]));
     }
+
+    public function spread(...$args)
+    {
+        return $this->response->withStringBody(json_encode(['args' => $args]));
+    }
 }