0

as the title states I have a problem with my application, which was updated from Laravel 5.6 to Laravel 9 recently. After the update there was no problem with anything (we did not use PHPUnit tests before). A few days we decided to start using Laravel testing with phpunit.

When running php artisan test there is no problem with the tests, but when using the command vendor/bin/phpunit tests/ there is an exception thrown:

Tests\Unit\ExampleTest::testBasicTest ErrorException: Cannot modify header information - headers already sent by (output started at ...\vendor\phpunit\phpunit\src\Util\Printer.php:104)

I tried using composer dependencies and phpunit xml file from clear Laravel 9 project - I copied the whole composer.json and ran composer update but the issue persisted


EDIT:

The tests that are in this application now are the basic tests that are shipped with Laravel (2 Example tests with assertTrue(true) and assertStatus(200) for url '/'). We plan to start using the tests but we stumbled upon this problem when automatizing the CI/CD in git repo.

As for the middleware in application, we only use custom middleware for assigning language, however I also disabled the middleware for testing.

The url for '/' executes this function:

$partners = Partner::orderBy('created_at', 'desc')->get();
$references = Reference::orderBy('created_at', 'desc')->take(6)->get();
return view('web.pages.index', compact('partners','references'));
Lukas Grofcik
  • 457
  • 1
  • 3
  • 15
  • 1
    That was a very risky move, migrate from laravel 5.6 to 9 without tests, you are a sabage! but, going back to the question. Could you share what is that test doing? Could you also share what is being run (for example, if you are running an HTTP test, share custom middlewares, the controller, etc) – matiaslauriti Oct 21 '22 at 11:13
  • Hey, I updated the question with the answers for you – Lukas Grofcik Oct 21 '22 at 11:28

1 Answers1

0

Alright, my mistake, the problem was that there was a code adding headers in api routes that should not have been there.

Lukas Grofcik
  • 457
  • 1
  • 3
  • 15