title: phpunit and http content-type
body: <p>I have an API built in Laravel (Dingo) and it works perfectly. However I have a problem with implementing phpunit to unit test my API</p>
  
  <pre><code>class ProductControllerTest extends TestCase
  {
      public function testInsertProductCase()
      {
          $data = array(
              , "description" =&gt; "Expensive Pen"
              , "price" =&gt; 100
          );
  
          $server = array();                        
          $this-&gt;be($this-&gt;apiUser);
          $this-&gt;response = $this-&gt;call('POST', '/products', [], [], $server, json_encode($data));
          $this-&gt;assertTrue($this-&gt;response-&gt;isOk());
          $this-&gt;assertJson($this-&gt;response-&gt;getContent());
      }
  
  }
  </code></pre>
  
  <p>meanwhile my API endpoint points to this controller function</p>
  
  <pre><code>private function store()
  {
  
      // This always returns null
      $shortInput = Input::only("price");
      $rules = [
              "price" =&gt; ["required"]
      ];
      $validator = Validator::make($shortInput, $rules);
  
      // the code continues
      ...
  }
  </code></pre>
  
  <p>However it always fail, because the API can't recognise the payload. Input::getContent() returns the JSON but Input::only() returns blank. Further investigation this is because Input::only() only returns value if the content type of the request payload is on JSON</p>
  
  <p>So ... how do I set my phpunit code above to use content-type application/json ? I am assuming it must have something to do with <code>$server</code> but I don't know what</p>
  
  <p>Edit:
  There are actually 2 problems with my original thinking</p>
  
  <ol>
  <li>Input::getContent() works because I fill the sixth parameter but Input::only() doesn't work because i didn't fill the third parameter. Thanks to @shaddy</li>
  <li>How to set content-type in phpunit request header is still unanswered</li>
  </ol>
  
  <p>Thanks heaps</p>