maxfilatov / phpuaca

PHPUnit Autocomplete Assistant (PhpStorm plugin)
50 stars 24 forks source link

Add support for Prophecy property, argument and return type completion #23

Closed deeky666 closed 8 years ago

deeky666 commented 8 years ago

Closes #20

Adds support for Prophecy autocompletion when referencing a property, argument variable or method return type. Requirement is though, that property, method parameter or method return type are type hinted properly via PHP DocBlocks.

Examples:

Property

class FooTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var \Prophecy\Prophecy\ObjectProphecy|\Bar
     */
    private $bar;

    /**
     * @var \Foo
     */
    private $foo;

    protected function setUp()
    {
        $this->bar = $this->prophesize(\Bar::class);
        $this->foo = new \Foo($this->bar->reveal());
    }

    public function testDoSomething()
    {
        $this->bar->foo()->willReturn('foo');

        $this->assertSame('foo', $this->foo->doSomething());
    }
}

Argument

class EvaNovaTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var \Foo
     */
    private $foo;

    protected function setUp()
    {
        $this->foo = new \Foo();
    }

    public function testDoSomething()
    {
        $bar = $this->prophesize(\Bar::class);

        $this->doSomething($bar);
    }

    /**
     * @param \Prophecy\Prophecy\ObjectProphecy|\Bar $bar
     */
    private function doSomething($bar)
    {
        $bar->foo()->willReturn('foo');

        $this->assertSame('foo', $this->foo->doSomething($bar->reveal()));
    }
}

Method return type

class FooTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var \Foo
     */
    private $foo;

    protected function setUp()
    {
        $this->foo = new \Foo();
    }

    public function testDoSomething()
    {
        $bar = $this->createBar();

        $bar->foo()->willReturn('foo');

        $this->assertSame('foo', $this->foo->doSomething($bar->reveal()));
    }

    /**
     * @return \Prophecy\Prophecy\ObjectProphecy|\Bar
     */
    private function createBar()
    {
        return $this->prophesize(\Bar::class);
    }
}
maxfilatov commented 8 years ago

@deeky666 thanks!