Answers.Body: <p>You could try setting PHPUnit's <a href="http://phpunit.de/manual/current/en/appendixes.annotations.html#appendixes.annotations.runInSeparateProcess" rel="nofollow noreferrer"><code>@runInSeparateProcess</code> flag</a>, as <a href="https://stackoverflow.com/questions/9745080/test-php-headers-with-phpunit?rq=1">discussed here</a>.</p>
  
  <p>However, it sounds as though you're attempting to use PHPUnit for acceptance or integration tests, when it's really designed to be used for unit testing.</p>
  
  <p>A couple of options:</p>
  
  <ol>
  <li>You could mock the <code>JsonHelper::sendJsonHeaders</code> method, but that may prove tricky;</li>
  <li>You could use something like <a href="http://docs.behat.org/en/v2.5/" rel="nofollow noreferrer">Behat</a> for integration testing. This may be more appropriate for a controller.</li>
  </ol>
  
  <p>Stephen</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-12T06:54:03.843Z
Answers.Text: Thanks for you answer. I created my test case for unit testing in order to cover a controller already developed and then start with T.D.D.
  I generally use Behat/Mink for acceptance tests or B.D.D.
  BTW I found an interesting example that explain better plugin development https://github.com/adrianmacneil/cocktailrecipes
  The approach suggested here is to make a partial mock of the controller using Mockery to mock parent methods as returnJson.
  Thanks anyway.
Answers.UserDisplayName: Alessio Evangelista
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-11T17:54:28.657Z
Answers.LastActivityDate: 2014-08-11T17:54:28.657Z
Answers.LastEditDate: 2017-05-23T12:38:53.957Z
Answers.UserDisplayName: Stephen Lewis
Answers.Body: <p>You can run phpunit with --stderr to redirect the phpunit output to stderr.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-27T10:00:41.810Z
Answers.LastActivityDate: 2014-08-27T10:00:41.810Z
Answers.UserDisplayName: Raymond Schouten
Body: <p>I'm trying to cover the plugin controller with unit tests, but when I try to run phpunit this error shows up:</p>
  
  <blockquote>
    <p>Warning: Cannot modify header information - headers already sent by (output started at /craft/app/vendor/phpunit/phpunit/src/Util/Printer.php:172 ) in /craft/craft/app/helpers/JsonHelper.php on line 25</p>
  </blockquote>
  
  <p>The same error indicates also line 26 and 27 of JsonHelper.php</p>
  
  <p>Did someone already had this issue? Can somebody help me on this?</p>
  
  <p>Thank you very much.</p>
  
Tags: <plugin-development><json>
Title: PHPUnit - Warning: "Header already sent"
ThreadText: # PHPUnit - Warning: "Header already sent"
  
  (Asked by: username_0 on 2014-08-11)
  
  I'm trying to cover the plugin controller with unit tests, but when I try to run phpunit this error shows up:
  
  > Warning: Cannot modify header information - headers already sent by (output started at /craft/app/vendor/phpunit/phpunit/src/Util/Printer.php:172 ) in /craft/craft/app/helpers/JsonHelper.php on line 25
  
  The same error indicates also line 26 and 27 of JsonHelper.php
  
  Did someone already had this issue? Can somebody help me on this?
  
  Thank you very much.
  
  **Tags:** plugin-development, json
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2014-08-11. Score: 3 | Accepted answer
  
  You could try setting PHPUnit's [`@runInSeparateProcess` flag](http://phpunit.de/manual/current/en/appendixes.annotations.html#appendixes.annotations.runInSeparateProcess), as [discussed here](https://stackoverflow.com/questions/9745080/test-php-headers-with-phpunit?rq=1).
  
  However, it sounds as though you're attempting to use PHPUnit for acceptance or integration tests, when it's really designed to be used for unit testing.
  
  A couple of options:
  
  1. You could mock the `JsonHelper::sendJsonHeaders` method, but that may prove tricky;
  2. You could use something like [Behat](http://docs.behat.org/en/v2.5/) for integration testing. This may be more appropriate for a controller.
  
  username_1
  
  > **Comments:**
  > **username_0**: Thanks for you answer. I created my test case for unit testing in order to cover a controller already developed and then start with T.D.D. I generally use Behat/Mink for acceptance tests or B.D.D. BTW I found an interesting example that explain better plugin development https://github.com/adrianmacneil/cocktailrecipes The approach suggested here is to make a partial mock of the controller using Mockery to mock parent methods as returnJson. Thanks anyway.  
  
  ---
  
  ### Answer by username_2 on 2014-08-27. Score: -1
  
  You can run phpunit with --stderr to redirect the phpunit output to stderr.
  
  
  ---
  
  