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

Phpstan Prophecy Laravel Package

jangregor/phpstan-prophecy

PHPStan extension for phpspec/prophecy that improves type inference in tests. It teaches PHPStan the real types returned from Prophecy workflows like prophesize(), willExtend(), and reveal(), so your revealed doubles are understood as the mocked class.

View on GitHub
Deep Wiki
Context7

phpstan-prophecy

Close Integrate Merge Triage

Latest Stable Version Total Downloads

Violinist Enabled

Provides a phpspec/prophecy extension for phpstan/phpstan.

Installation

Run

composer require --dev jangregor/phpstan-prophecy

Configuration

Automatic

When using phpstan/extension-installer, no further setup is required.

Manual

When not using phpstan/extension-installer, extension.neon needs to be included in phpstan.neon:

 includes:
+	- vendor/jangregor/phpstan-prophecy/extension.neon

Usage

prophesize() and reveal()

<?php

use PHPUnit\Framework;

final class ExampleTest extends Framework\TestCase
{
    public function testSomething(): void
    {
        $prophecy = $this->prophesize(SomeModel::class);

        $testDouble = $prophecy->reveal();

        // ...
    }
}

:bulb: With this extension enabled, phpstan/phpstan will understand that $testDouble is an instance of SomeModel.

prophesize(), willExtend(), and reveal()

<?php

use PHPUnit\Framework;

final class ExampleTest extends Framework\TestCase
{
    public function testSomething(): void
    {
        $prophecy = $this->prophesize()->willExtend(SomeModel::class);

        $testDouble = $prophecy->reveal();

        // ...
    }
}

:bulb: With this extension enabled, phpstan/phpstan will understand that $testDouble is an instance of SomeModel.

prophesize(), willImplement(), and reveal()

<?php

use PHPUnit\Framework;

final class ExampleTest extends Framework\TestCase
{
    public function testSomething(): void
    {
        $prophecy = $this->prophesize(SomeModel::class)->willImplement(SomeInterface::class);

        $testDouble = $prophecy->reveal();

        // ...
    }
}

:bulb: With this extension enabled, phpstan/phpstan will understand that $testDouble is an instance of SomeModel that also implements SomeInterface.

Method Predictions

<?php

use PHPUnit\Framework;

final class ExampleTest extends Framework\TestCase
{
    public function testSomething(): void
    {
        $prophecy = $this->prophesize(SomeModel::class);

        $prophecy
            ->doubleTheNumber(Argument::is(2))
            ->willReturn(4);

        $testDouble = $prophecy->reveal();

        // ...
    }
}

:bulb: With this extension enabled, phpstan/phpstan will understand that $prophecy accepts method calls to all methods that are implemented by its prophesized class (or additionally implemented interfaces, when using willImplement()).

Method Arguments

:exclamation: Currently here are no checks in place to validate the arguments of methods that are invoked on prophecies.

Development

A development environment is provided via .docker/Dockerfile.

Run

$ docker build --tag phpstan-prophecy .docker/

to build and tag the Docker image.

Run

$ docker run -it --rm  --volume "$PWD":/var/www/html --workdir /var/www/html phpstan-prophecy bash

to open a shell in the Docker container.

Changelog

Please have a look at CHANGELOG.md.

Contributing

Please have a look at CONTRIBUTING.md.

License

This package is licensed using the MIT License.

Please have a look at LICENSE.md.

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
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
php-http/client-implementation
phpcr/phpcr-implementation
cucumber/gherkin-monorepo
haydenpierce/class-finder
psr/simple-cache-implementation