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.
composer require --dev phpspec/prophecy-phpunit.PHPUnit\Framework\TestCase and use Prophecy\PhpUnit\ProphecyTrait;.$this->prophesize(ServiceInterface::class) to generate test doubles.->reveal() — e.g., $mock->process()->willReturn('ok').new ServiceConsumer($mock->reveal()).prophesize(LoggerInterface::class)) for looser coupling and clearer intent.Argument Constraints for Robustness: Use Argument::type(), Argument::exact(), or custom predicates via Argument::that() to avoid brittle string/identity matches.reveal() to prevent "unexpected call" exceptions from missed setup.prophesize() (v2.3+) for IDE autocomplete and static analysis — no more @var annotations for doubles.reveal() Must Follow Expectations: Calling reveal() prematurely (e.g., in constructor args before setting willReturn()) silently breaks prophecy tracking — build expectations first.shouldBeCalled()/shouldNotBeenCalled() or shouldHaveBeenCalled() after execution — for willReturn()-only cases, verify with --testdox or manual assertion counts.prophesize(), it will override the trait method (silent failure risk).phpspec/prophecy-phpunit: ^2.0; newer versions (v2.2+) require PHP ≥8.2 and Prophecy ≥1.18.^2.5^2.4^2.2^2.1-vvv and capture prophecy-specific output; failures show which argument constraints failed, often clearer than PHPUnit’s native mocks.How can I help you explore Laravel packages today?