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
Mockery Pdo

Mockery Pdo Laravel Package

mpyw/mockery-pdo

Experimental BDD-style PDO mocking library built on mockery/mockery. Define expectations for prepare/bind/execute and return rows via fetch/fetchAll in a fluent API, making PDO-based code easy to test on PHP 8.2+.

View on GitHub
Deep Wiki
Context7

[Experimental] BDD-style PDO Mocking Library for Mockery

Frequently asked questions about Mockery Pdo
How do I install mpyw/mockery-pdo in a Laravel project?
Run `composer require mpyw/mockery-pdo:VERSION@alpha` in your project root. Ensure your project uses PHP 8.2+ and Mockery 1.6.12+. The package is experimental, so check the latest alpha release for compatibility.
Can I use this package with Laravel 9 or older?
No, this package requires PHP 8.2+, which aligns with Laravel 10+. For Laravel 9 or older, you’ll need to either upgrade or explore alternatives like SQLite in-memory databases or legacy Mockery-based solutions.
How do I mock a PDO statement with named parameters like `:email`?
Use the fluent chain: `$pdo->shouldPrepare('SELECT * FROM users WHERE email = :email')->shouldBind()->value('email', 'test@example.com')`. This sets up expectations for the named parameter binding before execution.
Does this package support binding boolean values in PDO?
Yes, use `->boolValue('active', true)` in your expectation chain to mock boolean parameters. This ensures type safety when testing queries with boolean conditions.
How do I simulate row-by-row fetching instead of `fetchAll()`?
Use `->shouldStartFetching()->fetchReturns((object)['id' => 1])->fetchEnds()` to define progressive row fetching. This mimics PDO’s `fetch()` behavior for iterative result handling.
Will this work with Laravel Eloquent queries?
Yes, but you’ll need to mock the underlying PDO instance Eloquent uses. For complex queries (e.g., raw SQL with dynamic parameters), ensure your mock expectations align with the actual SQL generated by Eloquent.
Are there any known issues with PHP 8.2’s new features (e.g., named args, read-only properties)?
The package is designed for PHP 8.2+ and should work with its features, but test edge cases like sealed classes or constructor property promotion. Report issues to the GitHub repo if you encounter compatibility problems.
What alternatives exist if I can’t upgrade to PHP 8.2?
Consider Laravel’s built-in `DatabaseMocker` trait, SQLite in-memory databases, or forking this package to drop the PHP 8.2 requirement. Alternatives like `dbal/mock` (Doctrine) may also fit legacy stacks.
How do I test transactions or error cases with this package?
Extend the mock to include `shouldBeginTransaction()` or `shouldThrow(new PDOException())` in your expectation chain. For transactions, ensure rollback behavior is mocked if needed.
Does this package support testing `bindValue()` vs. `execute([...])` parameter binding?
Yes, you can mock both. Use `->shouldBind()->value('key', 'value')` for `bindValue()` or `->shouldExecute(['value1', 'value2'])` for array binding in `execute()`. The package validates both approaches.
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.
besmartand-pro/php-quality-config
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity