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.


You could try setting PHPUnit's @runInSeparateProcess flag, as discussed here.

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 for integration testing. This may be more appropriate for a controller.


  • 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 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. Aug 12 '14 at 6:54

You can run phpunit with --stderr to redirect the phpunit output to stderr.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.