title: How can I create a MockResponse with statusCode 400 header for MockHttpClient?
body: <p>I would like to test different responses from an API using symfony/http-client, but how can I create statusCode 400?</p>
  <p>This is what I tried:</p>
  <pre><code> public static function mockShipmentResponseFail(): MockResponse
  {
      $body = [
          'HttpStatusCode' =&gt; 400,
          'HttpStatusDescription' =&gt; 'Bad Request',
          'Message' =&gt; 'One or more shipments are invalid',
          'Errors' =&gt; [
              'Message' =&gt; 'The first line of the address must be 35 characters or less.',
              'Cause' =&gt; 'DestinationAddressLine1',
              'ErrorCode' =&gt; 'E1433', //Invalid field
              'ErrorId' =&gt; '932478fg83r7gf'
          ]
      ];
  
      return new MockResponse([json_encode($body)], ['http_code' =&gt; 400]);
  }
  </code></pre>
  <p>And use it like this:</p>
  <pre><code>$responses = [CourierServiceTest::mockLoginResponse(), CourierServiceTest::mockShipmentResponseFail()];
  $mockClient = new MockHttpClient($responses);
  $someService = new SomeService($mockClient, $request-&gt;server);
  $apiResponse = $someService-&gt;orders($tmpOrder1-&gt;getId());
  $responseArray = json_decode($apiResponse-&gt;getContent(), true);
  
  $this-&gt;assertEquals(400, $apiResponse-&gt;getStatusCode());
  $this-&gt;assertJson($apiResponse-&gt;getContent());
  </code></pre>
  <p>Unfortunately I receive the following error:</p>
  <blockquote>
  <p>Symfony\Component\HttpClient\Exception\ClientException : HTTP 400
  returned for &quot;https://api.someservice.net/api/&quot;.</p>
  </blockquote>
  <pre><code>try {
              $apiResponse = $this-&gt;client-&gt;request('POST', $url, [
                  'headers' =&gt; [
                      'accept' =&gt; 'application/json',
                      'content-type' =&gt; 'application/json',
                      other headers
                  ],
                  'body' =&gt; [
                      $body
                  ]
              ]);
          } catch (ClientException $exception) {
              return $exception-&gt;getResponse();
          }
  </code></pre>