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

Phpunit Easymock Laravel Package

mnapoli/phpunit-easymock

A lightweight bridge between PHPUnit and EasyMock for PHP. Quickly create, replay, and verify mocks from your test cases with minimal boilerplate, helping you write clear unit tests using the familiar EasyMock-style workflow.

View on GitHub
Deep Wiki
Context7

Getting Started

Install via Composer: composer require --dev mnapoli/phpunit-easymock. The package provides a simple, fluent API to generate mock objects without boilerplate—ideal for writing fast, isolated unit tests. Start by using EasyMock::make() to create mocks of interfaces or classes. For example:

$mock = EasyMock::make(Service::class);
$mock->method('doSomething')->willReturn('result');

The first use case is typically mocking dependencies in your tests to isolate the unit under test—replacing real services with controllable, inspectable stand-ins.

Implementation Patterns

  • Fluent setup: Chain expectations (->method('foo')->with('bar')->willReturn('baz')) for readability.
  • Partial mocks: Use EasyMock::partialMock() to mock only specific methods while retaining real implementations of others.
  • Property injection: Mocks support property mocking via ->property('name')->willReturn('value').
  • Type hints: Works seamlessly with PHP type declarations and PSR standards—ideal for modern Laravel apps with contract-based dependencies.
  • Integration with Laravel: Use in feature/unit tests to mock repositories, external clients (e.g., HTTP clients), or services resolved via Laravel’s container without real side effects.

Gotchas and Tips

  • Method name case sensitivity: method() is case-sensitive—'getUserId''getuserid'.
  • Static methods: Cannot be mocked; only instance methods are supported.
  • Final classes: Cannot be mocked (same limitation as PHP’s native mocking); use adapters or wrappers.
  • Real method calls: If you forget willReturn() or similar, method calls may trigger actual logic—always assert or stub side-effectful methods explicitly.
  • Debugging: Enable ->verbose() to see detailed expectations failures in test output.
  • Extension point: Create custom mock builders by extending EasyMock\Builder if your project has recurring mocking conventions (e.g., mocking API clients with identical base setup).
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
milesj/emojibase
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