Open danepowell opened 1 year ago
The second case may have been fixed since this was posted. (It works fine in my testing.) But I still see "void method exampleReturnsVoid result used
" in the third case.
I'm using v7.1
of the plugin in PhpStorm 2022.3.3
with the following library versions:
$ composer info \*phpunit/phpunit; composer info \*phpspec/prophecy; composer info \*phpspec/prophecy-phpunit
phpunit/phpunit 9.6.6 The PHP Unit Testing framework.
phpspec/prophecy v1.17.0 Highly opinionated mocking framework for PHP 5.3+
phpspec/prophecy-phpunit v2.0.1 Integrating the Prophecy mocking library in PHPUnit test cases
I tested with these classes:
<?php
namespace Example;
class Foo
{
public function exampleReturnsBool(): bool {
return true;
}
public function exampleReturnsBar(): Bar {
return new Bar();
}
public function exampleReturnsVoid(): void {
}
}
<?php
namespace Example;
class Bar
{
}
<?php
namespace Example;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
class ExampleTest extends TestCase {
use ProphecyTrait;
public function testSomething(): void {
$foo = $this->prophesize(Foo::class);
$foo->exampleReturnsBool()->willReturn(FALSE); // works great
$foo->exampleReturnsBar()->willReturn(new Bar); // works great
$foo->exampleReturnsVoid()->shouldBeCalled(); // PhpStorm complains "void method exampleReturnsVoid result used"
}
}
Confirmed, I think the void return type is the only troublemaker now. Updated the issue title to match.
Also, it seems like much of this plugin has been baked into PhpStorm itself, maybe we need to follow this bug: https://youtrack.jetbrains.com/issue/WI-68395/Do-not-report-Void-method-result-used-for-PhpSpec-Prophecy-test-calls
I have a class Foo with several methods. Some return built-in types (bool, string), others return objects (class Bar).
It seems like when prophesizing Foo, this plugin works for the methods that return built-in types but not objects with a custom class, or methods that return void.