Skip to content

Throw xPDOException when ContainerInterface lacks required 'config' entry#279

Merged
opengeek merged 1 commit intomodxcms:3.xfrom
opengeek:fix/269-psr11-container
Apr 7, 2026
Merged

Throw xPDOException when ContainerInterface lacks required 'config' entry#279
opengeek merged 1 commit intomodxcms:3.xfrom
opengeek:fix/269-psr11-container

Conversation

@opengeek
Copy link
Copy Markdown
Member

@opengeek opengeek commented Apr 1, 2026

What changed and why

xPDO::initConfig() silently fell back to a minimal default config when a PSR-11 ContainerInterface was passed without a 'config' entry, hiding the broken API contract from callers. The fix adds an explicit xPDOException in that case, making the required contract clear at construction time rather than producing mysterious runtime failures.

Closes #269.

Files and methods changed

  • src/xPDO/xPDO.phpinitConfig(): add else branch throwing xPDOException when container lacks 'config' entry.
  • test/xPDO/Test/xPDOPsr11InitTest.php — new test file (2 test methods).
  • test/sqlite.phpunit.xml, test/mysql.phpunit.xml, test/pgsql.phpunit.xml, test/complete.phpunit.xml — new test file registered in Complete testsuite.

Cross-driver impact

Universal. initConfig() runs before any driver-specific code. All four driver configs updated.

Test coverage

New: test/xPDO/Test/xPDOPsr11InitTest.php — 2 tests (regression + positive path).
Full suite (sqlite): Tests: 432, Assertions: 598, Skipped: 1 — zero failures.

Breaking change assessment

Behavior change for callers passing a ContainerInterface without a 'config' entry — they now receive an explicit exception instead of silent misconfiguration. Callers using the PSR-11 path correctly are unaffected. This is an intentional correction of a broken API contract, not introduced by design.

AI Disclosure

This fix was developed using an AI-assisted workflow. AI agents (Claude) wrote tests, code, and performed initial code review under the direction of the project maintainer (@opengeek), who reviewed the final diff, validated the approach, and takes responsibility for the submission.

Contributors

No external contributor. Follow-on from PR #265 (PSR-3 logger, merged 2026-03-08).

…ntry

Previously, passing a PSR-11 container without a 'config' entry to xPDO
caused initConfig() to silently fall back to a minimal default config
array, hiding the broken API contract from the caller. Now an explicit
xPDOException is thrown, making the required contract clear.

Closes modxcms#269.
@opengeek opengeek merged commit 8883ed1 into modxcms:3.x Apr 7, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Initialization with PSR-11 container relies on an implicit config entry

1 participant