title: Test a REST get request
body: <p>How do I <strong>test a GET request</strong> of a REST API with PHPUnit 4.1? I use the Slim PHP-Framework and could manage to test the <strong>response code but not the body or header</strong>.
  This is what I have so far:</p>
  
  <p>TestClass:  </p>
  
  <pre><code>class AssetTest extends PHPUnit_Framework_TestCase
  {
  
  public function request($method, $path, $options = array())
  {
      // Capture STDOUT
      ob_start();
  
      // Prepare a mock environment
      Environment::mock(array_merge(array(
          'REQUEST_METHOD' =&gt; $method,
          'PATH_INFO' =&gt; $path,
          'SERVER_NAME' =&gt; 'slim-test.dev',
      ), $options));
  
      $app = new \Slim\Slim();
      $this-&gt;app = $app;
      $this-&gt;request = $app-&gt;request();
      $this-&gt;response = $app-&gt;response();
  
      // Return STDOUT
      return ob_get_clean();
  }
  
     public function get($path, $options = array()){
        $this-&gt;request('GET', $path, $options);
     }
  
     public function testGetAssets(){
        $this-&gt;get('/asset');
        $this-&gt;assertEquals('200', $this-&gt;response-&gt;status());
     }
  }
  </code></pre>
  
  <p>If my JSON response of <a href="http://example.com/asset" rel="nofollow">http://example.com/asset</a> looks like this (Code 200):</p>
  
  <pre><code>[
    {
      "AssetID": "4b0be88b9e853",
      "AssetStatusID": "1"
    }
  ]
  </code></pre>