I am currently working on a PHP Laminas application. I am new to Laminas and PHPUnit. This application is working correctly in web mode (apache and development server). I am adding unit tests recently. Unfortunately, I am getting this error when I try to run my first test case.
Laminas\ServiceManager\Exception\ServiceNotCreatedException : Service with name "Laminas\Session\Config\ConfigInterface" could not be created. Reason: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time
...
Caused by
PHPUnit\Framework\Error\Warning: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time
I am using PHPUnit 9.6.10, PHP 7.4.20 and Laminas 3.0.1. I followed this tutorial.
I have researched a lot about this issue, but I cannot see what really the issue is.
This is my test case:
<?php
namespace PortadaTest\Controller;
use Portada\Controller\IndexController;
use Laminas\Stdlib\ArrayUtils;
use Laminas\Test\PHPUnit\Controller\AbstractHttpControllerTestCase;
class PortadaControllerTest extends AbstractHttpControllerTestCase
{
protected $traceError = false;
protected function setUp(): void
{
$configOverrides = [];
$this->setApplicationConfig(ArrayUtils::merge(
include 'config/application.config.php',
$configOverrides
));
parent::setUp();
}
public function testIndexActionCanBeAccessed()
{
$this->dispatch('/');
$this->assertResponseStatusCode(200);
$this->assertModuleName('application');
$this->assertControllerName('application_index');
$this->assertControllerClass('IndexController');
$this->assertMatchedRouteName('home');
}
}
I have already consulted these resources:
- ini_set(): Headers already sent. You cannot change the session module's ini settings at this time in codeigniter
- https://github.com/Codeception/module-symfony/issues/87
- https://discourse.laminas.dev/t/zend-session-error-with-phpunit-and-php-7-2-but-not-7-1/712
Maybe I don't understand everything, but I'm not sure how to get a solution for it.