From b51188bec52ded69dd94e854ffa20d7ee5e7b78d Mon Sep 17 00:00:00 2001
From: Jonathan Sacksick <jonathan.sacksick@gmail.com>
Date: Thu, 30 Mar 2023 13:32:05 +0300
Subject: [PATCH] Fix the failing tests.

---
 tests/src/Functional/RegistrationTest.php | 31 ++++++++++++-----------
 1 file changed, 16 insertions(+), 15 deletions(-)

diff --git a/tests/src/Functional/RegistrationTest.php b/tests/src/Functional/RegistrationTest.php
index f8bd639..1a55ae0 100644
--- a/tests/src/Functional/RegistrationTest.php
+++ b/tests/src/Functional/RegistrationTest.php
@@ -10,6 +10,7 @@ use Drupal\Tests\jsonapi\Functional\JsonApiRequestTestTrait;
 use Drupal\Tests\jsonapi\Functional\ResourceResponseTestTrait;
 use Drupal\user\UserInterface;
 use GuzzleHttp\RequestOptions;
+use Symfony\Component\HttpFoundation\Response;
 
 /**
  * Tests JSON:API Resource User registration.
@@ -78,10 +79,10 @@ final class RegistrationTest extends BrowserTestBase {
 
     $response = $this->request('POST', $url, $request_options);
     if ($register_setting === UserInterface::REGISTER_ADMINISTRATORS_ONLY) {
-      $this->assertSame(403, $response->getStatusCode(), $response->getBody());
+      $this->assertSame(403, $response->getStatusCode(), $response->getBody()->getContents());
     }
     else {
-      $this->assertSame(201, $response->getStatusCode(), $response->getBody());
+      $this->assertSame(201, $response->getStatusCode(), $response->getBody()->getContents());
 
       if ($register_setting === UserInterface::REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL) {
         $this->assertCount(2, $this->drupalGetMails());
@@ -119,11 +120,11 @@ final class RegistrationTest extends BrowserTestBase {
       ],
     ];
     $response = $this->request('POST', $url, $request_options);
-    $this->assertSame(422, $response->getStatusCode(), $response->getBody());
+    $this->assertSame(422, $response->getStatusCode(), $response->getBody()->getContents());
     $document = Json::decode((string) $response->getBody());
     $this->assertEquals([
       [
-        'title' => 'Unprocessable Entity',
+        'title' => Response::$statusTexts[422],
         'status' => '422',
         'detail' => 'No password provided.',
         'links' => [
@@ -143,11 +144,11 @@ final class RegistrationTest extends BrowserTestBase {
       ],
     ];
     $response = $this->request('POST', $url, $request_options);
-    $this->assertSame(422, $response->getStatusCode(), $response->getBody());
+    $this->assertSame(422, $response->getStatusCode(), $response->getBody()->getContents());
     $document = Json::decode((string) $response->getBody());
     $this->assertEquals([
       [
-        'title' => 'Unprocessable Entity',
+        'title' => Response::$statusTexts[422],
         'status' => '422',
         'detail' => 'name: You must enter a username.',
         'source' => [
@@ -155,7 +156,7 @@ final class RegistrationTest extends BrowserTestBase {
         ],
       ],
       [
-        'title' => 'Unprocessable Entity',
+        'title' => Response::$statusTexts[422],
         'status' => '422',
         'detail' => 'name: This value should not be null.',
         'source' => [
@@ -163,7 +164,7 @@ final class RegistrationTest extends BrowserTestBase {
         ],
       ],
       [
-        'title' => 'Unprocessable Entity',
+        'title' => Response::$statusTexts[422],
         'status' => '422',
         'detail' => 'mail: Email field is required.',
         'source' => [
@@ -183,11 +184,11 @@ final class RegistrationTest extends BrowserTestBase {
       ],
     ];
     $response = $this->request('POST', $url, $request_options);
-    $this->assertSame(422, $response->getStatusCode(), $response->getBody());
+    $this->assertSame(422, $response->getStatusCode(), $response->getBody()->getContents());
     $document = Json::decode((string) $response->getBody());
     $this->assertEquals([
       [
-        'title' => 'Unprocessable Entity',
+        'title' => Response::$statusTexts[422],
         'status' => '422',
         'detail' => 'name: The username cannot begin with a space.',
         'source' => [
@@ -207,7 +208,7 @@ final class RegistrationTest extends BrowserTestBase {
       ],
     ];
     $response = $this->request('POST', $url, $request_options);
-    $this->assertSame(201, $response->getStatusCode(), $response->getBody());
+    $this->assertSame(201, $response->getStatusCode(), $response->getBody()->getContents());
 
     $config->set('verify_mail', TRUE);
     $config->save();
@@ -223,11 +224,11 @@ final class RegistrationTest extends BrowserTestBase {
       ],
     ];
     $response = $this->request('POST', $url, $request_options);
-    $this->assertSame(422, $response->getStatusCode(), $response->getBody());
+    $this->assertSame(422, $response->getStatusCode(), $response->getBody()->getContents());
     $document = Json::decode((string) $response->getBody());
     $this->assertEquals([
       [
-        'title' => 'Unprocessable Entity',
+        'title' => Response::$statusTexts[422],
         'status' => '422',
         'detail' => 'A Password cannot be specified. It will be generated on login.',
         'links' => [
@@ -248,7 +249,7 @@ final class RegistrationTest extends BrowserTestBase {
       ],
     ];
     $response = $this->request('POST', $url, $request_options);
-    $this->assertSame(201, $response->getStatusCode(), $response->getBody());
+    $this->assertSame(201, $response->getStatusCode(), $response->getBody()->getContents());
   }
 
   /**
@@ -279,7 +280,7 @@ final class RegistrationTest extends BrowserTestBase {
       ],
     ];
     $response = $this->request('POST', $url, $request_options);
-    $this->assertSame(400, $response->getStatusCode(), $response->getBody());
+    $this->assertSame(400, $response->getStatusCode(), $response->getBody()->getContents());
 
     // @codingStandardsIgnoreStart
     /* Blocked on https://www.drupal.org/project/jsonapi_resources/issues/3105792
-- 
GitLab