Browse Source

Make tests work in PHP7.4 as well.

Mark Story 2 years ago
parent
commit
9cf4547669

+ 3 - 2
tests/TestCase/Controller/ControllerFactoryTest.php

@@ -884,11 +884,12 @@ class ControllerFactoryTest extends TestCase
      */
     public function testInvokePassedParamUnsupportedReflectionType(): void
     {
+        $this->skipIf(version_compare(PHP_VERSION, '8.0', '<='), 'Unions require PHP 8');
         $request = new ServerRequest([
-            'url' => 'test_plugin_three/dependencies/unsupportedTypedUnion',
+            'url' => 'test_plugin_three/unionDependencies/typedUnion',
             'params' => [
                 'plugin' => null,
-                'controller' => 'Dependencies',
+                'controller' => 'UnionDependencies',
                 'action' => 'typedUnion',
                 'pass' => ['1'],
             ],

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

@@ -61,11 +61,6 @@ class DependenciesController extends Controller
         return $this->response->withStringBody(json_encode(compact('one')));
     }
 
-    public function typedUnion(string|int $one)
-    {
-        return $this->response->withStringBody(json_encode(compact('one')));
-    }
-
     /**
      * @param mixed $any
      * @return \Cake\Http\Response

+ 36 - 0
tests/test_app/TestApp/Controller/UnionDependenciesController.php

@@ -0,0 +1,36 @@
+<?php
+declare(strict_types=1);
+
+namespace TestApp\Controller;
+
+use Cake\Controller\ComponentRegistry;
+use Cake\Controller\Controller;
+use Cake\Event\EventManagerInterface;
+use Cake\Http\Response;
+use Cake\Http\ServerRequest;
+use stdClass;
+
+/**
+ * UnionDependenciesController class
+ *
+ * Separate from Dependencies Controller because unions are not supported in PHP 7.4
+ */
+class UnionDependenciesController extends Controller
+{
+    public function __construct(
+        ?ServerRequest $request = null,
+        ?Response $response = null,
+        ?string $name = null,
+        ?EventManagerInterface $eventManager = null,
+        ?ComponentRegistry $components = null,
+        ?stdClass $inject = null
+    ) {
+        parent::__construct($request, $response, $name, $eventManager, $components);
+        $this->inject = $inject;
+    }
+
+    public function typedUnion(string|int $one)
+    {
+        return $this->response->withStringBody(json_encode(compact('one')));
+    }
+}