title: Test PHP headers with PHPUnit
body: <p>I'm trying to use PHPunit to test a class that outputs some custom headers.</p>
  
  <p>The problem is that on my machine this:</p>
  
  <pre><code>&lt;?php
  
  class HeadersTest extends PHPUnit_Framework_TestCase {
  
      public function testHeaders()
      {
          ob_start();
  
          header('Location: foo');
          $headers_list = headers_list();
          header_remove();
  
          ob_clean();
  
          $this-&gt;assertContains('Location: foo', $headers_list);
      }
  }
  </code></pre>
  
  <p>or even this:</p>
  
  <pre><code>&lt;?php
  
  class HeadersTest extends PHPUnit_Framework_TestCase {
  
      public function testHeaders()
      {
          ob_start();
  
          header('Location: foo');
          header_remove();
  
          ob_clean();
      }
  }
  </code></pre>
  
  <p>return this error:</p>
  
  <pre><code>name@host [~/test]# phpunit --verbose HeadersTest.php 
  PHPUnit 3.6.10 by Sebastian Bergmann.
  
  E
  
  Time: 0 seconds, Memory: 2.25Mb
  
  There was 1 error:
  
  1) HeadersTest::testHeaders
  Cannot modify header information - headers already sent by (output started at /usr/local/lib/php/PHPUnit/Util/Printer.php:173)
  
  /test/HeadersTest.php:9
  
  FAILURES!
  Tests: 1, Assertions: 0, Errors: 1.
  </code></pre>
  
  <p>This looks as if there is something else outputting to the terminal before the test runs even though there is no other file included and there is no other character before the beginning of the PHP tag. Could it be something inside PHPunit that is causing this?</p>
  
  <p><strong>What could the issue be?</strong></p>