eloquent/phony-phpunit
Integration of the Phony mocking/stubbing library with PHPUnit, providing helpers to use Phony in your test suite. Note: this package is no longer maintained; see the linked statement and consider alternatives or the main Phony repo.
Pros:
createMock() or getMockBuilder(). Ideal for testing Laravel services, repositories, or Eloquent models where dependency isolation is critical.when()->thenReturn(), anInstanceOf()) reduces test verbosity, improving readability and maintainability—especially for complex interactions (e.g., mocking API clients, event dispatchers, or database transactions).object type hints), aligning with Laravel’s modern PHP versions.Cons:
Illuminate\Contracts or service container bindings). Requires manual setup for Laravel-specific use cases.Strategic Alignment:
Technical Debt:
Adoption Scope:
Illuminate\Contracts) that this package doesn’t address?Alternatives:
Ramp-Up:
Laravel/PHPUnit Ecosystem:
Illuminate\Contracts or custom services).Non-Laravel PHP Projects:
Assessment Phase:
composer require --dev eloquent/phony-phpunit in a staging environment).Pilot Phase:
createMock()/getMockBuilder() with Phony’s mock()/stub().// Before (PHPUnit)
$mock = $this->createMock(SomeService::class);
$mock->method('fetchData')->willReturn([]);
// After (Phony)
$mock = Phony::mock(SomeService::class);
$mock->when('fetchData')->thenReturn([]);
verify() instead of expects()).Gradual Rollout:
Long-Term Strategy:
Laravel-Specific Considerations:
App\Services\AnalyticsService instead of AnalyticsServiceInterface).partialMock() (if available) or manual stubbing for container bindings.with() clauses) natively.PHPUnit Plugins:
phpunit-db-testcase). Test in isolation first.CI/CD:
# GitHub Actions snippet
services:
php:
image: php:8.1
steps:
- run: composer require --dev phpunit/phpunit:^9 eloquent/phony-phpunit
composer require --dev eloquent/phony-phpunit
composer.json under require-dev:
"eloquent/phony-phpunit": "^7.1"
--filter to test migrated suites in isolation:
phpunit --filter TestSuiteWithPhony
How can I help you explore Laravel packages today?