Skip to content
Snippets Groups Projects
Unverified Commit 05a71ed6 authored by Klaus Purer's avatar Klaus Purer Committed by GitHub
Browse files

refactor(phpstan): Fix PHPStan reports for test base class (#3104477)

parent 6516b060
Branches
Tags
No related merge requests found
Showing
with 154 additions and 89 deletions
......@@ -16,9 +16,9 @@ class ArrayUnitTest extends CoderSniffUnitTest
*
* @param string $testFile The name of the file being tested.
*
* @return array(int => int)
* @return array<int, int>
*/
public function getErrorList($testFile=null)
protected function getErrorList(string $testFile)
{
switch ($testFile) {
case 'ArrayUnitTest.inc':
......@@ -49,9 +49,9 @@ class ArrayUnitTest extends CoderSniffUnitTest
*
* @param string $testFile The name of the file being tested.
*
* @return array(int => int)
* @return array<int, int>
*/
public function getWarningList($testFile=null)
protected function getWarningList(string $testFile)
{
switch ($testFile) {
case 'ArrayUnitTest.inc':
......
......@@ -16,9 +16,9 @@ class DisallowLongArraySyntaxUnitTest extends CoderSniffUnitTest
*
* @param string $testFile The name of the file being tested.
*
* @return array(int => int)
* @return array<int, int>
*/
public function getErrorList($testFile=null)
protected function getErrorList(string $testFile)
{
switch ($testFile) {
case 'DisallowLongArraySyntaxUnitTest.2.inc':
......@@ -37,9 +37,11 @@ class DisallowLongArraySyntaxUnitTest extends CoderSniffUnitTest
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
* @param string $testFile The name of the file being tested.
*
* @return array<int, int>
*/
public function getWarningList()
protected function getWarningList(string $testFile)
{
return [];
......
......@@ -14,9 +14,11 @@ class ClassCreateInstanceUnitTest extends CoderSniffUnitTest
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
* @param string $testFile The name of the file being tested.
*
* @return array<int, int>
*/
public function getErrorList()
protected function getErrorList(string $testFile)
{
return [
3 => 1,
......@@ -43,9 +45,11 @@ class ClassCreateInstanceUnitTest extends CoderSniffUnitTest
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
* @param string $testFile The name of the file being tested.
*
* @return array<int, int>
*/
public function getWarningList()
protected function getWarningList(string $testFile)
{
return [];
......
......@@ -14,9 +14,11 @@ class ClassDeclarationUnitTest extends CoderSniffUnitTest
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
* @param string $testFile The name of the file being tested.
*
* @return array<int, int>
*/
public function getErrorList()
protected function getErrorList(string $testFile)
{
return [
11 => 1,
......@@ -33,9 +35,11 @@ class ClassDeclarationUnitTest extends CoderSniffUnitTest
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
* @param string $testFile The name of the file being tested.
*
* @return array<int, int>
*/
public function getWarningList()
protected function getWarningList(string $testFile)
{
return [];
......
......@@ -16,9 +16,9 @@ class ClassFileNameUnitTest extends CoderSniffUnitTest
*
* @param string $testFile The name of the file being tested.
*
* @return array(int => int)
* @return array<int, int>
*/
public function getErrorList($testFile=null)
protected function getErrorList(string $testFile)
{
switch ($testFile) {
case 'ClassFileNameUnitTest.php':
......@@ -36,9 +36,11 @@ class ClassFileNameUnitTest extends CoderSniffUnitTest
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
* @param string $testFile The name of the file being tested.
*
* @return array<int, int>
*/
public function getWarningList()
protected function getWarningList(string $testFile)
{
return [];
......
......@@ -16,9 +16,9 @@ class FullyQualifiedNamespaceUnitTest extends CoderSniffUnitTest
*
* @param string $testFile The name of the file being tested.
*
* @return array(int => int)
* @return array<int, int>
*/
public function getErrorList($testFile=null)
protected function getErrorList(string $testFile)
{
switch ($testFile) {
case 'FullyQualifiedNamespaceUnitTest.inc':
......@@ -36,9 +36,11 @@ class FullyQualifiedNamespaceUnitTest extends CoderSniffUnitTest
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
* @param string $testFile The name of the file being tested.
*
* @return array<int, int>
*/
public function getWarningList()
protected function getWarningList(string $testFile)
{
return [];
......
......@@ -14,9 +14,11 @@ class PropertyDeclarationUnitTest extends CoderSniffUnitTest
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
* @param string $testFile The name of the file being tested.
*
* @return array<int, int>
*/
public function getErrorList()
protected function getErrorList(string $testFile)
{
return [16 => 2];
......@@ -29,9 +31,11 @@ class PropertyDeclarationUnitTest extends CoderSniffUnitTest
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
* @param string $testFile The name of the file being tested.
*
* @return array<int, int>
*/
public function getWarningList()
protected function getWarningList(string $testFile)
{
return [];
......
......@@ -14,9 +14,11 @@ class UnusedUseStatementUnitTest extends CoderSniffUnitTest
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
* @param string $testFile The name of the file being tested.
*
* @return array<int, int>
*/
public function getErrorList()
protected function getErrorList(string $testFile)
{
return [];
......@@ -29,9 +31,11 @@ class UnusedUseStatementUnitTest extends CoderSniffUnitTest
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
* @param string $testFile The name of the file being tested.
*
* @return array<int, int>
*/
public function getWarningList()
protected function getWarningList(string $testFile)
{
return [
5 => 1,
......
......@@ -14,9 +14,11 @@ class UseLeadingBackslashUnitTest extends CoderSniffUnitTest
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
* @param string $testFile The name of the file being tested.
*
* @return array<int, int>
*/
public function getErrorList()
protected function getErrorList(string $testFile)
{
return [8 => 1];
......@@ -29,9 +31,11 @@ class UseLeadingBackslashUnitTest extends CoderSniffUnitTest
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
* @param string $testFile The name of the file being tested.
*
* @return array<int, int>
*/
public function getWarningList()
protected function getWarningList(string $testFile)
{
return [];
......
......@@ -33,6 +33,13 @@ abstract class CoderSniffUnitTest extends TestCase
*/
protected $backupGlobals = false;
/**
* The path to the root folder of Coder.
*
* @var string
*/
private $rootDir = null;
/**
* The path to the standard's main directory.
*
......@@ -110,7 +117,7 @@ abstract class CoderSniffUnitTest extends TestCase
/**
* Should this test be skipped for some reason.
*
* @return void
* @return bool
*/
protected function shouldSkipTest()
{
......@@ -173,13 +180,9 @@ abstract class CoderSniffUnitTest extends TestCase
$filename = basename($testFile);
$oldConfig = $config->getSettings();
try {
$this->setCliValues($filename, $config);
$phpcsFile = new LocalFile($testFile, $ruleset, $config);
$phpcsFile->process();
} catch (RuntimeException $e) {
$this->fail('An unexpected exception has been caught: '.$e->getMessage());
}
$this->setCliValues($filename, $config);
$phpcsFile = new LocalFile($testFile, $ruleset, $config);
$phpcsFile->process();
$failures = $this->generateFailureMessages($phpcsFile);
$failureMessages = array_merge($failureMessages, $failures);
......@@ -229,10 +232,10 @@ abstract class CoderSniffUnitTest extends TestCase
/**
* Generate a list of test failures for a given sniffed file.
*
* @param PHP_CodeSniffer_File $file The file being tested.
* @param \PHP_CodeSniffer\Files\LocalFile $file The file being tested.
*
* @return array
* @throws PHP_CodeSniffer_Exception
* @throws \PHP_CodeSniffer\Exceptions\RuntimeException
*/
public function generateFailureMessages(LocalFile $file)
{
......@@ -450,9 +453,11 @@ abstract class CoderSniffUnitTest extends TestCase
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @param string $testFile The name of the file being tested.
*
* @return array<int, int>
*/
abstract protected function getErrorList();
abstract protected function getErrorList(string $testFile);
/**
......@@ -461,9 +466,11 @@ abstract class CoderSniffUnitTest extends TestCase
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
* @param string $testFile The name of the file being tested.
*
* @return array<int, int>
*/
abstract protected function getWarningList();
abstract protected function getWarningList(string $testFile);
/**
......
......@@ -14,9 +14,11 @@ class ClassCommentUnitTest extends CoderSniffUnitTest
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
* @param string $testFile The name of the file being tested.
*
* @return array<int, int>
*/
public function getErrorList()
protected function getErrorList(string $testFile)
{
return [8 => 1];
......@@ -29,9 +31,11 @@ class ClassCommentUnitTest extends CoderSniffUnitTest
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
* @param string $testFile The name of the file being tested.
*
* @return array<int, int>
*/
public function getWarningList()
protected function getWarningList(string $testFile)
{
return [];
......
......@@ -14,9 +14,11 @@ class DataTypeNamespaceUnitTest extends CoderSniffUnitTest
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
* @param string $testFile The name of the file being tested.
*
* @return array<int, int>
*/
public function getErrorList()
protected function getErrorList(string $testFile)
{
return [
15 => 1,
......@@ -34,9 +36,11 @@ class DataTypeNamespaceUnitTest extends CoderSniffUnitTest
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
* @param string $testFile The name of the file being tested.
*
* @return array<int, int>
*/
public function getWarningList()
protected function getWarningList(string $testFile)
{
return [];
......
......@@ -14,9 +14,11 @@ class DeprecatedUnitTest extends CoderSniffUnitTest
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
* @param string $testFile The name of the file being tested.
*
* @return array<int, int>
*/
public function getErrorList()
protected function getErrorList(string $testFile)
{
// Basic layout is wrong.
return [24 => 2];
......@@ -30,9 +32,11 @@ class DeprecatedUnitTest extends CoderSniffUnitTest
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
* @param string $testFile The name of the file being tested.
*
* @return array<int, int>
*/
public function getWarningList()
protected function getWarningList(string $testFile)
{
return [
// Has version x 2.
......
......@@ -14,9 +14,11 @@ class DocCommentAlignmentUnitTest extends CoderSniffUnitTest
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
* @param string $testFile The name of the file being tested.
*
* @return array<int, int>
*/
public function getErrorList()
protected function getErrorList(string $testFile)
{
return [
14 => 1,
......@@ -32,9 +34,11 @@ class DocCommentAlignmentUnitTest extends CoderSniffUnitTest
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
* @param string $testFile The name of the file being tested.
*
* @return array<int, int>
*/
public function getWarningList()
protected function getWarningList(string $testFile)
{
return [];
......
......@@ -16,9 +16,9 @@ class DocCommentStarUnitTest extends CoderSniffUnitTest
*
* @param string $testFile The name of the file being tested.
*
* @return array(int => int)
* @return array<int, int>
*/
public function getErrorList($testFile=null)
protected function getErrorList(string $testFile)
{
switch ($testFile) {
case 'DocCommentStarUnitTest.inc':
......@@ -39,9 +39,11 @@ class DocCommentStarUnitTest extends CoderSniffUnitTest
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
* @param string $testFile The name of the file being tested.
*
* @return array<int, int>
*/
public function getWarningList()
protected function getWarningList(string $testFile)
{
return [];
......
......@@ -16,9 +16,9 @@ class DocCommentUnitTest extends CoderSniffUnitTest
*
* @param string $testFile The name of the file being tested.
*
* @return array(int => int)
* @return array<int, int>
*/
public function getErrorList($testFile=null)
protected function getErrorList(string $testFile)
{
switch ($testFile) {
case 'DocCommentUnitTest.inc':
......@@ -50,9 +50,11 @@ class DocCommentUnitTest extends CoderSniffUnitTest
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
* @param string $testFile The name of the file being tested.
*
* @return array<int, int>
*/
public function getWarningList()
protected function getWarningList(string $testFile)
{
return [];
......
......@@ -16,9 +16,9 @@ class FileCommentUnitTest extends CoderSniffUnitTest
*
* @param string $testFile The name of the file being tested.
*
* @return array(int => int)
* @return array<int, int>
*/
public function getErrorList($testFile=null)
protected function getErrorList(string $testFile)
{
switch ($testFile) {
case 'FileCommentUnitTest.inc':
......@@ -60,9 +60,11 @@ class FileCommentUnitTest extends CoderSniffUnitTest
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
* @param string $testFile The name of the file being tested.
*
* @return array<int, int>
*/
public function getWarningList()
protected function getWarningList(string $testFile)
{
return [];
......
......@@ -16,9 +16,9 @@ class FunctionCommentUnitTest extends CoderSniffUnitTest
*
* @param string $testFile The name of the file being tested.
*
* @return array(int => int)
* @return array<int, int>
*/
public function getErrorList($testFile=null)
protected function getErrorList(string $testFile)
{
switch ($testFile) {
case 'FunctionCommentUnitTest.inc':
......@@ -93,9 +93,11 @@ class FunctionCommentUnitTest extends CoderSniffUnitTest
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
* @param string $testFile The name of the file being tested.
*
* @return array<int, int>
*/
public function getWarningList()
protected function getWarningList(string $testFile)
{
return [];
......
......@@ -14,9 +14,11 @@ class GenderNeutralCommentUnitTest extends CoderSniffUnitTest
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
* @param string $testFile The name of the file being tested.
*
* @return array<int, int>
*/
public function getErrorList()
protected function getErrorList(string $testFile)
{
return [
7 => 1,
......@@ -44,9 +46,11 @@ class GenderNeutralCommentUnitTest extends CoderSniffUnitTest
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
* @param string $testFile The name of the file being tested.
*
* @return array<int, int>
*/
public function getWarningList()
protected function getWarningList(string $testFile)
{
return [];
......
......@@ -14,9 +14,11 @@ class HookCommentUnitTest extends CoderSniffUnitTest
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
* @param string $testFile The name of the file being tested.
*
* @return array<int, int>
*/
public function getErrorList()
protected function getErrorList(string $testFile)
{
return [9 => 1];
......@@ -29,9 +31,11 @@ class HookCommentUnitTest extends CoderSniffUnitTest
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
* @param string $testFile The name of the file being tested.
*
* @return array<int, int>
*/
public function getWarningList()
protected function getWarningList(string $testFile)
{
return [];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment