Skip to content

feat!: add active and inactive methods to unit of work port - #43

Merged
lindyhopchris merged 2 commits into
nextfrom
feature/unit-of-work-active
Nov 14, 2026
Merged

lindyhopchris merged 2 commits into
nextfrom
feature/unit-of-work-active

Conversation

@lindyhopchris

Copy link
Copy Markdown
Member

Summary

Adds active() and inactive() to the UnitOfWork driven port, so callers can tell whether a unit of work is in progress. This is a breaking change. Every implementation of the interface must add both methods, so this PR targets next (7.x).

Changes

  • Contracts\Application\Ports\UnitOfWork: new active() and inactive() methods, with docblocks.
  • Testing\FakeUnitOfWork:
    • Implements both methods. It is active while the execute() callback runs, including on each retry, and inactive before and after, whether the callback committed, rolled back or threw.
    • Throws a RuntimeException if execute() is called while it is already active. This matches UnitOfWorkManager, which does not support nested units of work.
  • Tests: cover the fake's flag in each of those states and the new nested-call exception.
  • Docs:
    • units-of-work.md: the interface listing and the Laravel adapter example now include the new methods, and the Testing section describes the fake's behaviour.
    • upgrade.md: new 6.x to 7.x section.
  • CHANGELOG.md: new Unreleased Next Major heading above Unreleased, with a BREAKING entry.
  • CLAUDE.md: new guidance on breaking changes. They must target next, and on next their changelog entries go under Unreleased Next Major.

Note for reviewers

In the Laravel example, active() uses transactionLevel() > 0. That counts every open transaction on the connection, including ones not started through the adapter's execute(), such as the transaction RefreshDatabase wraps around each test.

Test plan

  • composer all passes (deptrac, phpstan, pint, phpunit)

🤖 Generated with Claude Code

lindyhopchris and others added 2 commits November 14, 2026 14:14
Adds active() and inactive() to the UnitOfWork driven port, so callers
can determine whether a unit of work is currently in progress. The
FakeUnitOfWork implements both and now throws if execute() is called
while it is already active.

BREAKING CHANGE: implementations of the UnitOfWork interface must add
the active() and inactive() methods.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lindyhopchris lindyhopchris self-assigned this Nov 14, 2026
@lindyhopchris
lindyhopchris merged commit 6548c0a into next Nov 14, 2026
2 checks passed
@lindyhopchris
lindyhopchris deleted the feature/unit-of-work-active branch November 16, 2026 10:27
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.

1 participant