2017 © Pedro Peláez
 

library prophesizer

Generates prophecy double stubs

image

prophesizer/prophesizer

Generates prophecy double stubs

  • Saturday, August 19, 2017
  • by lukashin
  • Repository
  • 0 Watchers
  • 0 Stars
  • 3 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 12 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Prophesizer

Generates a Prophecy Dummy for class/interface you want to prophesize, (*1)

Prophesizer inspects @docComment blocks in your code and creates method prophecies according to specified @return, @throws and @param docTags, (*2)

@return and @throws samples generated in ->will(){...} closure, (*3)

@param int $id used to check parameters with Argument::type('int') etc., (*4)

Example

public function someUnitTest()
{
    $service = $this->prophesize('Service\SomeService'); ///
}    

Press Ctrl+S and line with /// will be transformed into, (*5)

public function someUnitTest()
{
    // $service = $this->prophesize('Service\SomeService');
    $service = $this->getSomeServiceDouble(); // todo: edit predictions!
}
/**
 * @return \Service\SomeService
 */
private function getSomeServiceDouble()
{
    $someServiceProphecy = $this->prophesize('Service\SomeService');

    /** @noinspection PhpUndefinedMethodInspection */
    $someServiceProphecy
        ->createSomething(
            Argument::type('int'),
            Argument::type('string'),
            Argument::allOf(Argument::type('DateTime'), Argument::type('null'))
        )
        ->will(function (array $args) {
            // todo: modify generated method double
            // throw new \SomeService\Exception('Thrown in SomeService::createSomething()');
            // return 999;
        })
        ->shouldBeCalled();
        //->shouldNotBeCalled();

    return $someServiceProphecy->reveal();
}

Why?

I'm tired of manual Dummies writing, (*6)

Installation

composer require prophesizer/prophesizer, (*7)

PhpStorm Settings / Tools / File Watchers / +, (*8)

-Watcher-
Name: prophesizer

-Options-
Show console : Error
[ ] Immediate file synchronization

-Watcher Settings-
File type    : PHP
Scope        : VCS / Changed Files
Program      : $ProjectFileDir$/vendor/bin/prophesizer
Arguments    : $FilePath$ $ProjectFileDir$ 
[x] Create output file from stdout 

PhpStorm / Edit watcher dialog, (*9)

prophesizer-watcher-setup, (*10)

The Versions

19/08 2017

dev-master

9999999-dev

Generates prophecy double stubs

  Sources   Download

MIT

The Requires

  • php >=5.3.6

 

The Development Requires

by Aleksei Lukashin