2017 © Pedro Peláez
 

library phpstan-prophecy

Provides a phpstan/phpstan extension for phpspec/prophecy

image

jangregor/phpstan-prophecy

Provides a phpstan/phpstan extension for phpspec/prophecy

  • Monday, July 16, 2018
  • by JanGregor
  • Repository
  • 4 Watchers
  • 16 Stars
  • 26,803 Installations
  • PHP
  • 13 Dependents
  • 0 Suggesters
  • 7 Forks
  • 1 Open issues
  • 6 Versions
  • 147 % Grown

The README.md

phpstan-prophecy

Close Integrate Merge Triage, (*1)

Latest Stable Version Total Downloads, (*2)

Violinist Enabled, (*3)

Provides a phpspec/prophecy extension for phpstan/phpstan., (*4)

Installation

Run, (*5)

composer require --dev jangregor/phpstan-prophecy

Configuration

Automatic

When using phpstan/extension-installer, no further setup is required., (*6)

Manual

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

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

Usage

prophesize() and reveal()

<?php

use PHPUnit\Framework;

final class ExampleTest extends Framework\TestCase
{
    private $prophecy;

    protected function setUp()
    {
        $this->prophecy = $this->prophesize(SomeModel::class);
    }

    public function testSomething(): void
    {
        $prophecy = $this->prophesize(SomeModel::class);

        $testDouble = $prophecy->reveal();

        // ...
    }

    public function testSomethingElse(): void
    {
        $testDouble = $this->prophecy->reveal();

        // ...
    }

    public function testSomethingDifferent(): void
    {
        $testDouble = $this->createProphecy()->reveal();

        // ...
    }

    private function createProphecy()
    {
        return $this->prophesize(SomeModel::class);
    }

}

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

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

<?php

use PHPUnit\Framework;

final class ExampleTest extends Framework\TestCase
{
    private $prophecy;

    protected function setUp()
    {
        $this->prophecy = $this->prophesize()->willExtend(SomeModel::class);
    }

    public function testSomething(): void
    {
        $prophecy = $this->prophesize()->willExtend(SomeModel::class);

        $testDouble = $prophecy->reveal();

        // ...
    }

    public function testSomethingElse(): void
    {
        $testDouble = $this->prophecy->reveal();

        // ...
    }

    public function testSomethingDifferent(): void
    {
        $testDouble = $this->createProphecy()->reveal();

        // ...
    }

    private function createProphecy()
    {
        return $this->prophesize(SomeModel::class)->willExtend(SomeInterface::class);
    }
}

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

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

<?php

use PHPUnit\Framework;

final class ExampleTest extends Framework\TestCase
{
    private $prophecy;

    protected function setUp()
    {
        $this->prophecy = $this->prophesize(SomeModel::class)->willImplement(SomeInterface::class);
    }

    public function testSomething(): void
    {
        $prophecy = $this->prophesize(SomeModel::class)->willImplement(SomeInterface::class);

        $testDouble = $prophecy->reveal();

        // ...
    }

    public function testSomethingElse(): void
    {
        $testDouble = $this->prophecy->reveal();

        // ...
    }

    public function testSomethingDifferent(): void
    {
        $testDouble = $this->createProphecy()->reveal();

        // ...
    }

    private function createProphecy()
    {
        return $this->prophesize(SomeModel::class)->willImplement(SomeInterface::class);
    }
}

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

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())., (*11)

Method Arguments

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

Development

A development environment is provided via .docker/Dockerfile., (*13)

Run, (*14)

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

to build and tag the Docker image., (*15)

Run, (*16)

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

to open a shell in the Docker container., (*17)

Changelog

Please have a look at CHANGELOG.md., (*18)

Contributing

Please have a look at CONTRIBUTING.md., (*19)

License

This package is licensed using the MIT License., (*20)

Please have a look at LICENSE.md., (*21)

The Versions

16/07 2018

dev-master

9999999-dev

Provides a phpstan/phpstan extension for phpspec/prophecy

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jan Gregor Emge-Triebel

16/07 2018

0.2.0

0.2.0.0

Provides a phpstan/phpstan extension for phpspec/prophecy

  Sources   Download

MIT

The Requires

 

by Jan Gregor Emge-Triebel

11/07 2018

0.1.x-dev

0.1.9999999.9999999-dev

Provides a phpstan/phpstan extension for phpspec/prophecy

  Sources   Download

MIT

The Requires

 

by Jan Gregor Emge-Triebel

11/07 2018

0.1.2

0.1.2.0

Provides a phpstan/phpstan extension for phpspec/prophecy

  Sources   Download

MIT

The Requires

 

by Jan Gregor Emge-Triebel

14/02 2018

0.1.1

0.1.1.0

  Sources   Download

The Requires

 

by Jan Gregor Emge-Triebel

08/12 2017

0.1

0.1.0.0

  Sources   Download

The Requires

 

by Jan Gregor Emge-Triebel