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'));
Alright, my mistake, the problem was that there was a code adding headers in api routes that should not have been there.