Skip to content

IBX-11939: Used the native session handler in the test kernel - #81

Merged
Steveb-p merged 1 commit into
5.0from
fix/native-session-handler-5.0
Nov 3, 2026
Merged

Steveb-p merged 1 commit into
5.0from
fix/native-session-handler-5.0

Conversation

@Steveb-p

@Steveb-p Steveb-p commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator
🎫 Issue IBX-11939

Description:

SchemaAlignmentTest errors on 5.0 in any package with ORM entities, on both install paths:

ErrorException: Warning: ini_set(): Session ini settings cannot be changed after headers have already been sent

PHP refuses session ini_set() calls once output has started, and in the CLI the first print counts as that. The bootstrap builds the schema before anything is printed, so it's fine there. PHPUnit 9 prints its header with print, 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 bad
Loading

Inside 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 good
Loading

Core's OrmEntitiesSchemaSubscriber runs SchemaTool for the package's entities, and SchemaTool fires postGenerateSchema to every listener on the entity manager. On Symfony 7 one of them is DoctrineBundle's PdoSessionHandlerSchemaListener, which needs session.handler. Core's SessionConfigurationPass points that at session.handler.native_file, and NativeFileSessionHandler's constructor calls ini_set('session.save_path', ...).

The test kernel mocks sessions anyway (session.storage.factory.mock_file), so it now sets ibexa.session.handler_id to the plain session.handler.native, which doesn't touch ini settings.

Not affected:

  • 4.6, the listener only exists since Symfony 6.3.
  • test-core's own SchemaAlignmentTest, its kernel has no ORM entities, so SchemaTool never runs.
  • Console commands like ibexa:install, Console writes with fwrite(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
Loading

✂ marks where each option cuts the chain:

Option What it does Downside
This PR (test-core) Test kernels set ibexa.session.handler_id to session.handler.native instead of core's file handler Test kernels stop using core's session handler. Harmless as far as I can tell: sessions are mocked anyway (mock_file storage), and no package test configures the handler
A (test-core) A compiler pass in IbexaTestKernel removes DoctrineBundle's pdo_session_handler_schema_listener service Depends on DoctrineBundle's service id, and on running before it attaches its listeners. The listener only does something for a PdoSessionHandler, which no test kernel uses
B (test-core) A compiler pass makes session.handler.native_file lazy, so the listener's instanceof check never constructs it Fragile: breaks as soon as the listener calls anything on the handler
C (core) OrmEntitiesSchemaSubscriber runs SchemaTool through an EntityManagerDecorator with an empty event manager Behaviour change in core, on all three tiers (below)

C 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:install too. It just doesn't blow up there, because Console writes with fwrite(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 SchemaAlignmentTest to 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.

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
Steveb-p merged commit 6928d1d into 5.0 Nov 3, 2026
24 of 25 checks passed
@Steveb-p
Steveb-p deleted the fix/native-session-handler-5.0 branch November 3, 2026 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants