I'm running into an issue related to Mockery. On the next snippet, intelephense underlines the use of $info because the function expects a value of type TableInformation, but I'm actually giving it a MockInterface (because I'm testing).
namespace Tests;
use Mockery;
use My\TableInformation;
// ...
$info = Mockery::mock(TableInformation::class);
$consumer = myFunction($info); // Expected type 'My\TableInformation'. Found 'Mockery\MockInterface'. intelephense(10006)
Is there any plan to allow for this kind of usage?
I tried to annotate the $info variable with /** @var My\TableInformation */ but intelephense does not seem to use that information to detect variable types...
You must include the variable name in the @var typehint -- /** @var My\TableInformation $info */ . It may be possible to improve this using metadata files, tracking this in #246 .
@bmewburn What about properties where I鈥檝e marked it as MockInterface (so my IDE gives me auto-complete), but the method I then pass that mock to expects a different type?
class FooTest extends TestCase
{
/** @var \Mockery\MockInterface */
private $foo;
protected function setUp()
{
parent::setUp();
$this->foo = Mockery::mock(Foo::class);
}
public function testCase()
{
// I want type-hinting of Mockery methods here...
$this->foo->shouldReceive('someMethod')->once();
// ...but VSCode complains that foo property is MockInterface here
FooClass::fooMethod($this->foo);
}
}
For now I think you'd have to type hint with a union type.
/** @var \Mockery\MockInterface|Foo */
private $foo;
If I understand correctly then it's really an intersect type, tracking this in #424
@bmewburn Great. Thank you 馃檪
@bmewburn tacking onto this, with v1.1.3 I'm still seeing:
Expected type 'ResponseInterface'. Found 'PHPUnit\Framework\MockObject\MockObject'.intelephense(10006)
/** @var MockObject|ResponseInterface */
private $_response;
protected function setup()
{
$this->_response = $this->createMock(ResponseInterface::class);
$this->_plugin = new GraphQLControllerPlugin(**$this->_response**);
}
Even after using the union type.
@damienwebdev #551 you could add @return MockObject|ResponseInterface to createMock as a workaround.
Most helpful comment
For now I think you'd have to type hint with a union type.
If I understand correctly then it's really an intersect type, tracking this in #424