Ini_set() return false and failed in laminas and PHP8

I have recently updated a zend project to Laminas and PHP8. It seems it works, but integration test is failed because ini_set() return false here.

\Laminas\Session\Config\SessionConfig::setStorageOption

I saw this warning as well.
ini_set(): Session ini settings cannot be changed after headers have already been sent in phpunit test

Any idea?

The project is Dockerized.

Do you use laminas-test?

Hi @froschdesign

in composer.json

“require-dev”: {
“phpunit/phpunit”: “^9”,
“laminas/laminas-test”: “^4”

These error is displayed when I run phpunit and show this line

/project/vendor/phpunit/phpunit/phpunit:98

Can you provide the related test and the method setUp if it is used?

@froschdesign

Just wanna mention, it worked before in zend and php7.4. I did not change the code and related test. just is updated to laminas and php8.

this comes from Module

 public function onBootstrap(MvcEvent $e): void
    {
        $eventManager = $e->getApplication()->getEventManager();
        $eventManager->attach(
            MvcEvent::EVENT_DISPATCH_ERROR,
            [$this, 'handleDispatchError'],
            100
        );
        $eventManager->attach(
            MvcEvent::EVENT_RENDER_ERROR,
            [$this, 'handleRenderError'],
            100
        );

        $serviceManager = $e->getApplication()->getServiceManager();

        /* @var $bypassAuth BypassAuth */
        $bypassAuth = $serviceManager->get(BypassAuth::class); // test failure pointed here
        $bypassAuth->attach($eventManager);
    }

global.php

return [
    // Session
    'session_config'                       => [
        'name'                => 'ubs_solo',
        'use_cookies'         => true,
        'cookie_path'         => '/ubs-solo',
        'cookie_secure'       => false,
        'cookie_httponly'     => true,
        //timeouts
        'cache_expire'        => 840,   
        'cookie_lifetime'     => 50400, 
        'gc_maxlifetime'      => 50400 * 1000,
        'remember_me_seconds' => 50400,
    ],
    'session_storage'                      => [
        'type' => Session\Storage\SessionArrayStorage::class,
    ],
  • I have got same test failures in all 7 tests.
    this is one of those test
 public function testIndexAction(): void
    {
        $this->dispatch('/page-api/product-outstanding', Request::METHOD_GET); // test failure mentioned here)

        $content = $this->getResponse()->getContent();
        static::assertNotEmpty($content);
        $this->assertResponseStatusCode(200);
        $this->assertControllerName(OutstandingControllerFactory::SERVICE);
        $this->assertActionName('index');
        $responseObject = json_decode($content, true);
        static::assertEquals('OK', $responseObject['state']);
        static::assertNotEmpty($responseObject['data']);
        static::assertArrayHasKey('groups', $responseObject['data']);
        static::assertArrayHasKey('products', $responseObject['data']['groups']);
        static::assertArrayHasKey('count', $responseObject['data']);
        static::assertArrayHasKey('filters', $responseObject['data']);
        static::assertArrayHasKey('totalCount', $responseObject['data']);

        static::assertArrayHasKey('structure', $responseObject['data']['filters']);
        static::assertArrayHasKey('underlying', $responseObject['data']['filters']);
        static::assertArrayHasKey('issuer', $responseObject['data']['filters']);
        static::assertArrayHasKey('cusip', $responseObject['data']['filters']);
        static::assertArrayHasKey('tenor', $responseObject['data']['filters']);
        static::assertArrayHasKey('maturityDate', $responseObject['data']['filters']);
        static::assertArrayHasKey('platform', $responseObject['data']['filters']);
        static::assertArrayHasKey('accountTypeEligibility', $responseObject['data']['filters']);
        static::assertArrayHasKey('tradeDate', $responseObject['data']['filters']);
    }

Hi @froschdesign

I have sent an API request to a Java application and expect to get response. I got 500 with a message that cookie does not have a special key like ‘myproject’

its already set in
\Laminas\Session\Config\SessionConfig::setStorageOption
$result = ini_set($key, $storageValue);

But I can not see this new set in browser inspection instead I see ‘PHPSESSID’.

My integration test is failed as well buy this error
ini_set(): Session ini settings cannot be changed after headers have already been sent

****Recently I updated the project to PHP8 and Lamins. Previously it worked well.

Any idea?