<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>

CC BY-SA 3.0
2014-08-12T06:54:03.843Z
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.
Alessio Evangelista
CC BY-SA 3.0
2014-08-11T17:54:28.657Z
2014-08-11T17:54:28.657Z
2017-05-23T12:38:53.957Z
Stephen Lewis
<p>You can run phpunit with --stderr to redirect the phpunit output to stderr.</p>

CC BY-SA 3.0
2014-08-27T10:00:41.810Z
2014-08-27T10:00:41.810Z
Raymond Schouten
<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>

<plugin-development><json>
PHPUnit - Warning: "Header already sent"
# 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.

Stephen

> **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.


---

