dev-master
9999999-devGenerates prophecy double stubs
MIT
The Requires
- php >=5.3.6
The Development Requires
by Aleksei Lukashin
Wallogit.com
2017 © Pedro Peláez
Generates prophecy double stubs
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)
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();
}
I'm tired of manual Dummies writing, (*6)
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)
, (*10)
Generates prophecy double stubs
MIT