Weave Code
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

Module Db Laravel Package

codeception/module-db

Database module for Codeception that handles connecting to a DB, running queries, and cleaning up between tests. Supports populating data, verifying records, and fast resets to keep acceptance and functional test suites reliable and repeatable.

View on GitHub
Deep Wiki
Context7

Getting Started

Start by installing the module via Composer: composer require --dev codeception/module-db. Then enable it in your codeception.yml or suite config (e.g., tests/acceptance.suite.yml) under modules: enabled. Configure the database connection using config with dsn, user, password, and optional cleanup settings (e.g., true to truncate tables after tests). The first use case is typically seeding a test database—use haveInDatabase(), grabFromDatabase(), or seeInDatabase() in your tests to assert or insert data.

Implementation Patterns

Use haveInDatabase() for creating isolated test data in single tables, and combine it with seeInDatabase() for assertions on persisted records. For multi-table scenarios, prefer factories (if using Laravel) or custom helper methods that call haveInDatabase() multiple times. Utilize grabFromDatabase() to fetch values (e.g., IDs) for dynamic test data setup. In cleanup mode (cleanup: false), manually roll back transactions using seeInDatabase() within before()/after() hooks if you need persistent data across multiple test steps. For Laravel projects, integrate with codeception/module-laravel to leverage model factories seamlessly.

Gotchas and Tips

⚠️ The cleanup setting is per-suite—misconfiguring it can cause false negatives from stale data. Always verify db connection settings match your test environment (e.g., use separate DB from dev/prod). ⚠️ When using MySQL, be aware of sql_mode strictness that may cause silent failures—override via DSN options if needed. ✅ Use debug: true in DB config temporarily to log raw SQL queries during debugging. ✅ For speed, disable cleanup during local CI runs and manually reset DB via codecept run --debug --steps to inspect state. ✅ Extend Codeception\Module\DB to add project-specific helpers (e.g., registerUser() with complex validation flows).

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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4