diff --git a/moodle/Sniffs/PHPUnit/TestCaseProviderSniff.php b/moodle/Sniffs/PHPUnit/TestCaseProviderSniff.php index b396072..5072602 100644 --- a/moodle/Sniffs/PHPUnit/TestCaseProviderSniff.php +++ b/moodle/Sniffs/PHPUnit/TestCaseProviderSniff.php @@ -193,6 +193,24 @@ protected function checkDataProvider( ); } + if (substr($methodName, -2) === '()') { + $fix = $file->addFixableWarning( + 'Data provider should not end with "()". "%s" provided.', + $pointer + 2, + 'dataProviderSyntaxMethodnameContainsParenthesis', + [ + $methodName, + ] + ); + + $methodName = substr($methodName, 0, -2); + if ($fix) { + $file->fixer->beginChangeset(); + $file->fixer->replaceToken($pointer + 2, $methodName); + $file->fixer->endChangeset(); + } + } + // Find the method itself. $classPointer = $file->findPrevious(T_CLASS, $pointer - 1); $providerPointer = MoodleUtil::findClassMethodPointer($file, $classPointer, $methodName); diff --git a/moodle/Tests/PHPUnitTestCaseProviderTest.php b/moodle/Tests/PHPUnitTestCaseProviderTest.php index 12e5e67..374d716 100644 --- a/moodle/Tests/PHPUnitTestCaseProviderTest.php +++ b/moodle/Tests/PHPUnitTestCaseProviderTest.php @@ -50,6 +50,14 @@ public function provider_phpunit_data_providers() { 'warnings' => [ ], ], + 'Provider has Parenthesis' => [ + 'fixture' => 'fixtures/phpunit/provider/provider_parents_test.php', + 'errors' => [ + ], + 'warnings' => [ + 6 => 'Data provider should not end with "()". "provider()" provided.', + ], + ], 'Provider Visibility' => [ 'fixture' => 'fixtures/phpunit/provider/provider_visibility_test.php', 'errors' => [ diff --git a/moodle/Tests/fixtures/phpunit/provider/provider_parents_test.php b/moodle/Tests/fixtures/phpunit/provider/provider_parents_test.php new file mode 100644 index 0000000..709f77e --- /dev/null +++ b/moodle/Tests/fixtures/phpunit/provider/provider_parents_test.php @@ -0,0 +1,15 @@ +