yoannrenard / phpunit-annotation-testcase

Use simple annotations to mock the world

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

phpunit-annotation-testcase

Build Status

Use simple annotations to mock the world!

Installing Dependencies

Use Composer and run :

$> composer require --dev yoannrenard/phpunit-annotation-testcase

Requirements

Run tests

$> bin/phpunit

Run using Docker

$> docker build -t pat .
$> docker run --rm -it -v ${PWD}:/app pat sh

Usage

<?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());
    }
}

About

Use simple annotations to mock the world

License:MIT License


Languages

Language:PHP 97.9%Language:Dockerfile 2.1%