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

Prophecy Phpunit Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

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:

  • How does it interact with Laravel's Mockery-based test helpers (e.g., fake() for facades)?
  • What's the migration path for existing tests using PHPUnit's createMock()?
  • Does it support Laravel's TestResponse assertions when mocking HTTP clients?

Integration Approach

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:

  1. Add package: composer require --dev phpspec/prophecy-phpunit
  2. Replace use PHPUnit\Framework\TestCase with use Prophecy\PhpUnit\ProphecyTrait in test classes
  3. Convert existing mocks:
    // Before
    $mock = $this->createMock(Service::class);
    // After
    $mock = $this->prophesize(Service::class);
    
  4. Gradually refactor expectations to use Prophecy syntax (e.g., $mock->method()->shouldBeCalled() instead of `expects()->
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
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
twbs/bootstrap4