Skip to content

Phase 6 — Unit of Work & Snapshot Engine

Choose a tag to compare

@Maatify Maatify released this 22 Nov 18:29
· 8 commits to main since this release

🚀 Release Notes — v1.0.2

Phase 6 — Unit of Work & Snapshot Engine

This release introduces a complete transactional layer on top of the in-memory storage system, enabling atomic operations, nested transactions, and deterministic rollback across all Fake Adapters (MySQL, Redis, MongoDB, DBAL).

Phase 6 significantly enhances reliability for complex repository testing and multi-step operations.


🔥 What's New

🧱 Unit of Work (UoW)

A new FakeUnitOfWork class provides transaction-like behavior:

  • begin() — start a new snapshot transaction
  • commit() — accept the changes
  • rollback() — revert to the previous snapshot
  • Nested transactions supported (stack-based snapshots)
  • transactional(callable) helper with automatic commit/rollback
  • Works with ALL fake adapters (MySQL, Redis, Mongo, DBAL)

📸 Snapshot Engine

Two new classes enable deterministic state saving & restoring:

  • SnapshotManager
  • SnapshotState

These provide:

  • Deep cloning of all tables & documents
  • Auto-increment counter preservation
  • Full export/import of FakeStorageLayer state
  • Immutable state objects for safe storage and reuse

🗄 Storage Layer Enhancements

FakeStorageLayer now supports:

  • exportState()
  • importState()

Allowing engine-wide rollback & restore across multiple adapters.


🧪 Tests Added

New PHPUnit suites:

  • FakeUnitOfWorkTest
  • SnapshotManagerTest

Validating:

  • Commit propagation
  • Rollback correctness
  • Nested snapshot behavior
  • Exception-safe rollback in transactional()

All tests pass under PHPUnit 11 and PHPStan Level Max.


📘 Documentation

Updated:

  • README.phase6.md
  • README.full.md
  • phase-output.json

All new architecture components are now documented in the main library spec.


🔧 Changes Summary

  • Added FakeUnitOfWork
  • Added SnapshotManager
  • Added SnapshotState
  • Updated FakeStorageLayer
  • Added tests for all new features
  • Updated documentation and metadata files

🏷 Version

v1.0.2
Backward compatible — no breaking changes.