Repository navigation
IBX-11939: Used the native session handler in the test kernel - #81
Merged
Merged
Conversation
Core points session.handler at its native file handler, whose constructor calls ini_set(). On Symfony 7, Doctrine's PdoSessionHandlerSchemaListener loads the handler whenever the ORM schema is generated, so a test that builds the schema (e.g. AbstractSchemaAlignmentTestCase in a package with ORM entities) fails once PHPUnit has printed output: "Session ini settings cannot be changed after headers have already been sent". Sessions are mocked in the test kernel, so the plain native handler does.
Steveb-p
marked this pull request as ready for review
October 30, 2026 13:05
ibexa-workflow-automation-1
Bot
requested review from
ViniTou,
alongosz,
barw4,
bnowak,
ciastektk,
konradoboza,
mikadamczyk,
tbialcz and
wiewiurdp
and removed request for
a team
October 30, 2026 16:09
alongosz
approved these changes
Nov 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description:
SchemaAlignmentTesterrors on 5.0 in any package with ORM entities, on both install paths:PHP refuses session
ini_set()calls once output has started, and in the CLI the firstprintcounts as that. The bootstrap builds the schema before anything is printed, so it's fine there. PHPUnit 9 prints its header withprint, then the test boots its own kernel and builds the schema again:flowchart LR A["Bootstrap<br/>nothing printed yet"] --> B["PHPUnit header<br/>print ⇒ headers sent"] --> C["SchemaAlignmentTest<br/>builds the schema again"] classDef warn fill:#FAEEDA,stroke:#854F0B,color:#633806 classDef bad fill:#FCEBEB,stroke:#A32D2D,color:#791F1F class B warn class C badInside that second
buildSchema():flowchart TD A["SchemaBuilder::buildSchema()<br/>dispatches BUILD_SCHEMA"] --> B["core's OrmEntitiesSchemaSubscriber<br/>SchemaTool fires postGenerateSchema"] B --> C["PdoSessionHandlerSchemaListener<br/>Symfony 6.3+, needs session.handler"] C -->|before| D["session.handler.native_file<br/>core's default"] C -->|this PR| E["session.handler.native<br/>PHP's own SessionHandler"] D --> F["ini_set('session.save_path')<br/>refused ⇒ ErrorException"] E --> G["no ini_set() call<br/>listener ignores it, test runs"] classDef bad fill:#FCEBEB,stroke:#A32D2D,color:#791F1F classDef good fill:#EAF3DE,stroke:#3B6D11,color:#27500A class D,F bad class E,G goodCore's
OrmEntitiesSchemaSubscriberrunsSchemaToolfor the package's entities, andSchemaToolfirespostGenerateSchemato every listener on the entity manager. On Symfony 7 one of them is DoctrineBundle'sPdoSessionHandlerSchemaListener, which needssession.handler. Core'sSessionConfigurationPasspoints that atsession.handler.native_file, andNativeFileSessionHandler's constructor callsini_set('session.save_path', ...).The test kernel mocks sessions anyway (
session.storage.factory.mock_file), so it now setsibexa.session.handler_idto the plainsession.handler.native, which doesn't touch ini settings.Not affected:
SchemaAlignmentTest, its kernel has no ORM entities, soSchemaToolnever runs.ibexa:install, Console writes withfwrite(STDOUT, ...), which doesn't mark headers as sent.Alternatives
This PR cuts the chain at its last link, by swapping the handler. It can be cut earlier too. I've tried each of these on taxonomy's 5.0 merge-up (with unpatched test-core it reproduces the error), and all of them pass on both install paths:
flowchart TD S["SchemaBuilder::buildSchema()"] --> O["core's OrmEntitiesSchemaSubscriber<br/>runs SchemaTool on the shared event manager"] O -->|"postGenerateSchema<br/>✂ C, ✂ A"| L["DoctrineBundle's PdoSessionHandlerSchemaListener<br/>its constructor takes session.handler"] L -->|"session.handler<br/>✂ B, ✂ this PR"| H["NativeFileSessionHandler::__construct()<br/>core's default handler"] H --> X["ini_set() refused ⇒ ErrorException"] classDef bad fill:#FCEBEB,stroke:#A32D2D,color:#791F1F class H,X bad✂ marks where each option cuts the chain:
ibexa.session.handler_idtosession.handler.nativeinstead of core's file handlermock_filestorage), and no package test configures the handlerIbexaTestKernelremoves DoctrineBundle'spdo_session_handler_schema_listenerservicePdoSessionHandler, which no test kernel usessession.handler.native_filelazy, so the listener'sinstanceofcheck never constructs itOrmEntitiesSchemaSubscriberrunsSchemaToolthrough anEntityManagerDecoratorwith an empty event managerC is the only one fixing the cause rather than the symptom. The subscriber only wants its own entities' tables, and already throws away whatever the other listeners add. But it still sets off all four of DoctrineBundle's schema listeners (DBAL cache adapter, remember-me tokens, PDO session handler, lock store), which instantiate their services for nothing - during
ibexa:installtoo. It just doesn't blow up there, because Console writes withfwrite(STDOUT, ...), which doesn't mark headers as sent.The catch is that a listener modifying one of Ibexa's own ORM tables would stop applying on the SchemaBuilderEvent path. I don't expect there are any, but I haven't checked every package. It'd also mean core PRs on 4.6, 5.0 and 6.0, and the merge-ups pinning a core branch instead of test-core.
Shouldn't we rather go with C? Or A, if we'd rather not touch core's behaviour. I'm keeping this PR as it is until we decide.
Needed by the 4.6 → 5.0 merge-ups that bring
SchemaAlignmentTestto 5.0 (ibexa/taxonomy#508 was the first one), and #82 is stacked on it. Will need a 5.0 → 6.0 merge-up afterwards, 6.0 gets the test case through #80.For QA:
No QA required.
Documentation:
No documentation required.