Highlighted class: tooltip methods

I have the following setup: I make fun of a non-abstract class with PHPUnit, but not all of its methods. Therefore, non-mocking methods still exist as a call to real methods in the layout.

And the question arises: how to hint that these methods are available (of course, with the appropriate signature)?

I will describe a little. Sample class:

class RealClass
{
    public function callApi(Api $api) {}

    public function doStuff(Foo $foo, Bar $bar) {}
}

Now I do in the test:

/** @var  \PHPUnit_Framework_MockObject_MockObject $mock */
$mock = $this->getMock('\RealClass', ['callApi']);

This will create mock only for callApi(), but then if in the test:

$mock->doStuff($foo, $bar);

My PHPStorm cannot find the method explicitly and assumes this is an error. How can I indicate that a method exists doStuff()and that the correct arguments are required?

@method , . @see, . , , return, mocks .

" " - , , - , . , , .

+4
1

MockObject, RealClass, - :

/** @var \RealClass|\PHPUnit_Framework_MockObject_MockObject $mock */
$mock = $this->getMock('\RealClass', ['callApi']);

PhpStorm, $mock PHPUnit MockObject RealClass, / .

( , ), use , :

<?php

use \RealClass;
use \PHPUnit_Framework_MockObject_MockObject as MockObject;

class YourTestClass
{
    public function yourTest()
    {
        // Because of the use statements (and the "as" alias rule) you can now:
        /** @var RealClass|MockObject $mock */
        $mock = $this->getMock('RealClass', ['callApi']);
    }
}
+3

Source: https://habr.com/ru/post/1608438/


All Articles