Strengths:
Str::, Arr::).final classes via proxies) critical for Laravel’s evolving ecosystem (e.g., PHP 8.1+ attributes, named arguments).Weaknesses:
bind(), singleton()), Facades, or Blade templating mocks.Pros:
composer require eloquent/phony-phpunit for PHPUnit (Laravel’s default).RefreshDatabase, MigrateFresh).register()/boot() methods.Cache::remember()).Mockery (if needed) for feature parity.Cons:
app()->bind()).createMock() in PHPUnit) or testing utilities (e.g., Laravel\Sanctum\PersonalAccessToken).Mockery (e.g., Phony::mock() vs. Mockery::mock()).dispatch() or delay() calls.event(new Event()) invocations.Http::fake() or Route::fake() interactions.AppServiceProvider mocking).Phony for complex mocks + Laravel’s built-in tools for simple cases.Phony work with Laravel’s PHPUnit bridge (e.g., createApplication())?Illuminate\Contracts interfaces (e.g., Authenticatable)?Phony vs. Mockery in Laravel’s test suite?spatie/phony-laravel)?Mockery + custom extensions cover Phony’s gaps with less risk?UserRepository).Http::post()) or database interactions.Str::slug()) or static methods.HttpTests, FeatureTests, or Pest/Testbench.DatabaseMigrations, DatabaseTransactions, or RefreshDatabase.UserRepository mock).eloquent/phony-phpunit for new unit tests.Mockery tests to Phony for procedural code.Phony for Laravel-specific needs (e.g., service container mocks).php-cs-fixer rule to standardize Phony syntax (e.g., mock() vs. createMock()).Phony usage in the team’s testing guidelines.| Laravel Component | Phony Support | Workaround |
|---|---|---|
| Eloquent Models | ✅ (Class mocking) | Use mock('App\Models\User') |
| Service Container | ❌ | Manually stub app()->bind() |
Facades (e.g., Cache::) |
❌ | Use Phony + Facade::swap() |
HTTP Client (Http::) |
❌ | Stub Illuminate\Support\Facades\Http |
Queues (Bus::fake()) |
❌ | Mock Illuminate\Bus\Dispatcher |
Events (Event::fake()) |
❌ | Stub Illuminate\Events\Dispatcher |
| Blade Views | ❌ | Mock Illuminate\View\Factory |
| PHPUnit Bridge | ✅ (via eloquent/phony-phpunit) |
Use Phony::mock() in tests |
Mockery for mocking classes/interfaces (e.g., UserRepository).// Before (Mockery)
$mock = Mockery::mock(UserRepository::class);
$mock->shouldReceive('find')->andReturn($user);
// After (Phony)
$handle = Phony::mock(UserRepository::class);
$handle->find->returns($user);
$repository = $handle->get();
Str::slug()) or static methods.$handle = mock('Str');
$handle->slug->with('test')->returns('test-slug');
Http::post()) alongside Laravel’s Http::fake().PhonyLaravel::mockServiceProvider()).Phony’s fluent API may simplify complex mocks.Phony breaks, tests may fail silently until discovered.Phony).Phony cheat sheet for the team.Phony compatibility issues early.Mockery for critical tests.How can I help you explore Laravel packages today?