Skip to content

Route the remaining ResultSet and Container throw sites through named constructors - #195

Merged
simon-mundy merged 2 commits into
php-db:0.6.xfrom
simon-mundy:exception/pr-6-resultset-container
Sep 29, 2026
Merged

simon-mundy merged 2 commits into
php-db:0.6.xfrom
simon-mundy:exception/pr-6-resultset-container

Conversation

@simon-mundy

Copy link
Copy Markdown
Member

Types of changes

  • Documentation improvement
  • New feature (non-breaking change which adds functionality)
  • QA improvement (unit/integration tests, CS fixes, etc.) that does not change code behavior

Checklist:

  • An issue has been created for this pull request.
  • I have added tests for my changes.
  • All new and existing tests passed.
  • Documentation has been updated accordingly.
  • This pull request targets the correct branch.

Description

PR 6 of 6 from #189, and the last: the throw sites outside the components #191 to #194 cover.

Stacked on #190. GitHub cannot base a cross-fork PR on a fork branch, so this targets 0.6.x and shows both commits. Only the second, 2f46c04e, belongs to this PR. Merge #190 first; I will rebase after. It does not depend on #191, #192, #193 or #194.

Message text is byte-identical, verified template by template against the original literals.

  • ResultSet\Exception\RuntimeException::forUnbufferedIteration().
  • ContainerException::forNonAdapterAwareDelegate(), plus factories for the three reasons that AdapterInterfaceFactory and AbstractAdapterInterfaceFactory were passing to forService() as inline strings: forMissingConfigService(), forMissingConfiguration() and forMissingDriver(). Each composes the reason into the SERVICE template, so the composed messages are verified as well as the templates.
  • The delegator's non-AdapterAware guard is retyped from the root Exception\RuntimeException to ContainerException, which extends it. A container failure should carry PSR-11's ContainerExceptionInterface, and nothing catching the old type is affected.

One documented exception to the convention

The delegator's "not found in container" guard must throw the ServiceManager's own ServiceNotFoundException — the container contract decides the type. I first extended that class so the template could live on it, and mago analyze correctly refused: Laminas annotates it @final. It is not final in PHP today, so runtime reflection and the test suite both accepted the subclass, but the annotation is a clear statement of intent and extending it would break when Laminas enforces it.

So this package owns the wording without owning the class: the template is ContainerException::MISSING_SERVICE and that one throw site renders it itself. docs/book/exceptions.md records it as the single place the convention does not apply, and why. Everywhere the thrown type is ours, the rule holds without exception.

Motivation and Context

Refs #189. Depends on #190.

Scope is deliberately limited to what the other PRs do not touch, so this does not conflict with them: ResultSet, Container and Adapter/Container. One literal assertion is left in test/unit/Container/TableIdentifierFactoryFactoryTest.php because it asserts Sql\Exception\InvalidArgumentException::EMPTY_SEPARATOR, a constant #192 introduces — it can be migrated in a follow-up once that lands.

With #191 to #194, this completes the conversion: no throw new remains anywhere in src/.

How has this been tested?

mago format --check, mago lint and mago analyze all exit 0. Full unit suite passes: 1630 tests, 3529 assertions.

Patch coverage measured locally at 16/16 lines, computed the way codecov/patch does, before pushing. #194 failed that check on a method whose test class had never declared it in #[CoversMethod], so coverage was executed but not attributed; this PR was checked against that trap up front.

@codecov

codecov Bot commented Sep 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@simon-mundy
simon-mundy force-pushed the exception/pr-6-resultset-container branch from 2f46c04 to 0eceb96 Compare September 28, 2026 22:52
… constructors

The last 5 throw sites outside the components covered by php-db#191 to php-db#194. Message
text is byte-identical, verified template by template against the originals.

- Add ResultSet\Exception\RuntimeException::forUnbufferedIteration()
- Add forNonAdapterAwareDelegate() to Exception\ContainerException, and give
  the three reasons that AdapterInterfaceFactory and
  AbstractAdapterInterfaceFactory passed as inline strings their own factories:
  forMissingConfigService(), forMissingConfiguration() and forMissingDriver(),
  each composing the reason into the SERVICE template
- Retype the delegator's non-AdapterAware guard from the root
  Exception\RuntimeException to ContainerException, which extends it, so the
  failure carries PSR-11's ContainerExceptionInterface as a container failure
  should
- Own the "not found in container" wording as ContainerException::MISSING_SERVICE
  while still throwing the ServiceManager's own ServiceNotFoundException. Laminas
  annotates that class @Final, so this package cannot own it; the throw site
  renders the template itself, which docs/book/exceptions.md now records as the
  single documented exception to the convention
- Derive the message assertions in the six test files the earlier PRs do not
  touch from the templates rather than restating them

One literal assertion is deliberately left in
test/unit/Container/TableIdentifierFactoryFactoryTest.php: it asserts
Sql\Exception\InvalidArgumentException::EMPTY_SEPARATOR, a constant php-db#192
introduces, so it can only be migrated once that has landed.

Signed-off-by: Simon Mundy <simon.mundy@peptolab.com>
@simon-mundy
simon-mundy force-pushed the exception/pr-6-resultset-container branch from 0eceb96 to de32800 Compare September 29, 2026 03:35
@simon-mundy simon-mundy added documentation Improvements or additions to documentation qa Improvements in quality assurance of the project RFC RFC issue or PR labels Sep 29, 2026
@github-project-automation github-project-automation Bot moved this to Todo in @phpdb Sep 29, 2026
@simon-mundy simon-mundy added this to the 0.6.0 milestone Sep 29, 2026
@simon-mundy simon-mundy self-assigned this Sep 29, 2026
@simon-mundy
simon-mundy requested a review from tyrsson September 29, 2026 03:46
@simon-mundy
simon-mundy merged commit bab0e38 into php-db:0.6.x Sep 29, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request qa Improvements in quality assurance of the project RFC RFC issue or PR

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants