phpspec/prophecy-phpunit
Integrates the Prophecy mocking library with PHPUnit for simpler, cleaner test doubles. Install via Composer and use the ProphecyTrait to call prophesize() inside your TestCase, set method predictions/returns, and reveal mocks for injection.
Architecture fit: This package integrates seamlessly with Laravel's default testing stack (PHPUnit) as a dev-only dependency. It replaces PHPUnit's native mocking with Prophecy's more expressive syntax, aligning perfectly with Laravel's test-driven development culture where precise mock interactions are critical for unit tests. The trait-based approach avoids inheritance conflicts with Laravel's TestCase base class.
Integration feasibility: Extremely high. Requires only a Composer require command and trait addition to test classes. No configuration changes needed for Laravel's test environment. The package has explicit version constraints for PHPUnit/PHP that match Laravel's supported ranges (e.g., Laravel 10+ uses PHPUnit 10+ which requires prophecy-phpunit ≥v2.1.0).
Technical risk: Low. The package has consistent release activity (6 releases in 2023-2024), MIT license, and is a thin wrapper around mature Prophecy library (3.6k stars). "Dependents: 0" is expected for this integration layer. Primary risk is version misalignment if Laravel upgrades PHPUnit without updating this package's constraints.
Key questions:
Mockery-based test helpers (e.g., fake() for facades)?createMock()?TestResponse assertions when mocking HTTP clients?Stack fit: Ideal for Laravel's unit tests where Prophecy's argument constraints (Argument::type(), Argument::that()) and precise expectation syntax improve test readability over PHPUnit's native mocks. Works alongside Laravel's HTTP test tools (e.g., TestResponse) since it only affects unit test mocking.
Migration path:
composer require --dev phpspec/prophecy-phpunituse PHPUnit\Framework\TestCase with use Prophecy\PhpUnit\ProphecyTrait in test classes// Before
$mock = $this->createMock(Service::class);
// After
$mock = $this->prophesize(Service::class);
$mock->method()->shouldBeCalled() instead of `expects()->How can I help you explore Laravel packages today?