Use simple annotations to mock the world!
Use Composer and run :
$> composer require --dev yoannrenard/phpunit-annotation-testcase
- Composer
- PHP >=8.0
$> bin/phpunit
$> docker build -t pat .
$> docker run --rm -it -v ${PWD}:/app pat sh
<?php
use Prophecy\Prophecy\ObjectProphecy;
use YoannRenard\PHPUnitAnnotation\TestCase\AnnotationTestCase;
class MyClassTest extends AnnotationTestCase
{
/**
* @var Foo|ObjectProphecy
*
* @mock <namespace>\Foo
*/
protected $fooMock;
/**
* @var Bar
*
* @factory("\YoannRenard\PHPUnitAnnotation\TestCase\Mock\Bar", params={"fooMock"})
*/
protected $bar;
}
will replace
<?php
use Prophecy\Prophecy\ObjectProphecy;
use PHPUnit\Framework\TestCase;
class MyClassTest extends TestCase
{
/**
* @var Foo|ObjectProphecy
*/
protected $fooMock;
/** @var Bar */
protected $bar;
/**
* @inheritdoc
*/
protected function setUp(): void
{
parent::setUp();
$this->fooMock = $this->prophesize(Foo::class);
$this->bar = new Bar($this->fooMock->reveal());
}
}