Which product ? Sonarcloud
Which language ? PHP
Which rule ? S1144
At the moment, in Unit Tests, we are getting Unused “private” methods should be removed rule violations on private
methods used with PHPDoc @dataProvider
annotation.
PHPStorm does not report these methods as unused and is perfectly able to link the annotation value to the method implementation.
I believe it’s a false-positive because, obviously, the method is used when executing the Unit Test.
Here is a code snippet :
class S1444Test extends TestCase
{
/**
* @dataProvider valueProvider
*/
public function testShouldCastValue(string $rawValue, int $castedValue) : void
{
// Given // When
$result = (int) $rawValue;
// Then
assertSame($castedValue, $result);
}
private function valueProvider() : array
{
return [
['1', 1],
['2', 2],
['wrong', 0]
];
}
}