Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Doctrine Test Bundle Laravel Package

dama/doctrine-test-bundle

A Symfony bundle that speeds up Doctrine tests by wrapping DBAL connections in a static driver and rolling back a transaction after each test, keeping tests isolated without schema rebuilds or fixture reloads. It also configures a PSR-6 static array cache.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Accelerating CI/CD Pipelines: Adopting this package directly addresses the bottleneck of slow database-driven tests, reducing test suite execution time by eliminating schema rebuilds and fixture reloads per test. This enables faster feedback loops for developers, particularly for teams with high test volume (e.g., >1000 tests) or complex Doctrine entities.
  • Shift from "Build" to "Buy" for Test Isolation: For teams already using Symfony/Doctrine, this package replaces custom test isolation logic (e.g., manual transactions, backup/restore scripts) with a maintained, battle-tested solution. Reduces technical debt in test infrastructure. v8.7.0 is a non-breaking minor release, reinforcing the low-risk "buy" case: adopting now does not put us on a forced-migration path.
  • Enabling Scalable Test Suites: Supports parallel test execution (via static connections) without race conditions, critical for large-scale monorepos or microservices with shared test databases.
  • Roadmap for Test Reliability: Aligns with initiatives to:
    • Improve flakiness: Isolated transactions prevent test pollution. New in v8.7.0: the bundle warns about transactions that were never closed — leaked transactions are a common root cause of lock contention, timeouts, and non-deterministic CI failures, so this turns a silent failure mode into an actionable signal. Budget a small amount of cleanup work when enabling it on legacy suites (expect an initial burst of warnings).
    • Support attribute-based testing (e.g., #[SkipDatabaseRollback] for edge cases like debugging).
    • Future-proofing: v8.7.0 explicitly allows PHPUnit 13, so the compatibility previously listed as roadmap is now shipped; Symfony 8+ and Doctrine 3.x remain the supported baseline.
  • Broadening Coverage Across Test Runners: v8.7.0 adds Behat 4 support, so teams standardizing on current Behat no longer need to pin an older version or maintain their own integration glue. This expands the package's applicability from PHPUnit-only suites to mixed PHPUnit + Behat estates.
  • Use Cases:
    • API/Controller Tests: Rollback database changes after each HTTP request test.
    • Integration Tests: Isolate multi-entity workflows without side effects.
    • Behat/Gherkin Scenarios: Automatically reset state between scenarios (where same-process execution is possible) — now validated against Behat 4.

When to Consider This Package

  • Adopt if:

    • Your test suite spends >30% of runtime on database operations (e.g., schema rebuilds, fixture loading).
    • You use Symfony + Doctrine and want to avoid custom transaction management.
    • Tests fail intermittently due to shared state (e.g., INSERT/UPDATE conflicts) or leaked transactions — v8.7.0's new warning surfaces the latter automatically.
    • Your team prioritizes CI speed (e.g., GitHub Actions, GitLab CI with timeouts).
    • You are on (or planning to move to) PHPUnit 13 or Behat 4 — both now supported without forking or pinning.
    • You need debuggability (temporary commits for inspection without modifying tests).
  • Look Elsewhere if:

    • Your tests require DDL changes (e.g., ALTER TABLE) that can’t be rolled back (use temporary test databases instead).
    • You use multi-process testing (e.g., Selenium, Dockerized tests) where static connections won’t work.
    • Your stack doesn’t support PHP 8.2+ (e.g., legacy PHP 7.4). Note the maintainer's CI now targets PHP 8.6, a forward-looking signal that the supported floor will keep rising; confirm against our upgrade calendar before committing.
    • You need cross-language test isolation (e.g., Python + PHP sharing a DB; consider test containers).
    • Your tests rely on implicit commits (e.g., MySQL’s AUTOCOMMIT=1; configure use_savepoints: true or refactor).

How to Pitch It (Stakeholders)

For Executives/Stakeholders:

"This package cuts test suite runtime by 50–80% by eliminating redundant database operations. For a team running 2,000 tests daily, that’s ~10–15 hours saved per week in CI costs—equivalent to 2 full-time engineers. It’s a zero-risk upgrade (MIT-licensed, used by Symfony’s demo app) that improves reliability while reducing infrastructure costs. No code changes needed; just install and enable. The newest release is a drop-in minor version that keeps us current with PHPUnit 13 and Behat 4, and adds automatic warnings for unclosed transactions — the kind of hidden defect that causes flaky builds and wasted engineering hours."

Key Outcomes: ✅ Faster releases: Shorter CI feedback loops. ✅ More reliable tests: No flakiness from shared state; leaked transactions now flagged. ✅ Lower cloud costs: Fewer failed retries due to timeouts. ✅ Future-proof: Current with PHPUnit 13, Behat 4, and modern PHP/Symfony stacks.


For Engineering Teams:

*"The DAMA Doctrine Test Bundle replaces manual transaction management with a smart, configurable wrapper that:

  • Rolls back all DB changes per test (no schema rebuilds or fixtures).
  • Caches metadata/queries in-memory (faster Doctrine operations).
  • Warns on transactions that were never closed (v8.7.0) — catches leaking code paths before they become CI flakiness.
  • Supports selective rollback skipping for debugging (e.g., #[SkipDatabaseRollback]).
  • Works with PHPUnit 13 and Behat 4 (both newly supported in v8.7.0) plus Symfony’s test utilities.

Implementation:

  1. Add to composer.json (dev dependency) — pin to ^8.7.
  2. Enable in bundles.php and phpunit.xml.
  3. Configure use_savepoints: true in Doctrine DBAL (if using DBAL <4).
  4. Run the suite once and triage the new unclosed-transaction warnings; fix or suppress intentionally.

Trade-offs:

  • Not for multi-process tests (e.g., Selenium).
  • Requires PHP 8.2+ (drop-in replacement for older versions exists); maintainer CI is already on PHP 8.6, so plan for the supported floor to advance.
  • Avoid DDL in tests (or use temporary commits for debugging).
  • Expect short-term noise from the new unclosed-transaction warnings on older suites.

Next Steps:

  • Benchmark current test suite runtime.
  • Validate compatibility with our Doctrine and Behat setup.
  • Pilot in a non-critical branch (e.g., feature flags); budget one sprint for warning cleanup."*
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
steadrun/laravel-monitor
labyrinthe/connect-laravel
elmogy/layan
drewdan/sentinel-client
dskripchenko/laravel-llm
fatryst/nuonuo
stevenay/myanfont
gmostafa/php-graphql-client
xeviant/paystack
snowsoft/faker
meditationsteps/blogetc
animalyoung/laravel-influxdb
onix-solutions/sms-telera
lonely-lights/prosetta
oxygen/data
oxygen/core
jengo/base
xiloryx/log-collector
a21ns1g4ts/filament-stripe
la-php/laravel-admin