title: Integration Testing JSON API Response
body: <p>I'm currently writing some tests for my API, and I'm curious to know if there is a better way to deal with this as I feel like this is the "hacky" way of doing things.</p>
  
  <p>Code example below:</p>
  
  <pre><code>public function testListingOfAllUsers()
  {
      $users = $this-&gt;createUsers();
  
      $client = $this-&gt;createClient();
      $client-&gt;request("GET", "/users/");
  
      $response = $client-&gt;getResponse();
      $content = $response-&gt;getContent();
      $decodedContent = json_decode($content);
  
      $this-&gt;assertTrue($response-&gt;isOk());
      $this-&gt;assertInternalType("array", $decodedContent-&gt;data);
      $this-&gt;assertCount(count($users), $decodedContent-&gt;data);
  
      foreach ($decodedContent-&gt;data as $data) {
          $this-&gt;assertObjectHasAttribute("attributes", $data);
          $this-&gt;assertEquals("users", $data-&gt;type);
      }
  }
  </code></pre>
  
  <p>I'm wondering if there's something better I can do to test my API matches the JSON API specification. Enlighten me! I'm pretty certain PHPUnit isn't my answer here.</p>