Browse Source

add setJsonHeader method to IntegrationTestTrait

Kevin Pfeifer 3 years ago
parent
commit
b67558e818

+ 16 - 1
src/TestSuite/IntegrationTestTrait.php

@@ -268,6 +268,21 @@ trait IntegrationTestTrait
     }
 
     /**
+     * Sets HTTP headers for the *next* request to be identified as JSON request.
+     *
+     * @return void
+     */
+    public function setJsonHeader(): void
+    {
+        $this->configRequest([
+            'headers' => [
+                'Accept' => 'application/json',
+                'Content-Type' => 'application/json',
+            ],
+        ]);
+    }
+
+    /**
      * Configures the data for the *next* request.
      *
      * This data is cleared in the tearDown() method.
@@ -281,7 +296,7 @@ trait IntegrationTestTrait
      */
     public function configRequest(array $data): void
     {
-        $this->_request = $data + $this->_request;
+        $this->_request = array_merge_recursive($data, $this->_request);
     }
 
     /**

+ 1 - 2
tests/TestCase/TestSuite/IntegrationTestTraitTest.php

@@ -158,11 +158,10 @@ class IntegrationTestTraitTest extends TestCase
      */
     public function testRequestBuilding(): void
     {
+        $this->setJsonHeader();
         $this->configRequest([
             'headers' => [
                 'X-CSRF-Token' => 'abc123',
-                'Content-Type' => 'application/json',
-                'Accept' => 'application/json',
             ],
             'base' => '',
             'webroot' => '/',