diff --git a/.gitignore b/.gitignore index dc851ab..d2b0a4a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,4 @@ /.vagrant/ /composer.lock /build/ -.phpunit.result.cache +/var/ diff --git a/CHANGELOG.md b/CHANGELOG.md index 67d14f4..09d8acf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to `phpcs-type-sniff` will be documented in this file. Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) principles. +## Unreleased +### Changed +- Min `phpcs` version to 3.10 + ## 81.5.2 - 2024-04-05 ### Changed - Min phpcs version to 3.9 diff --git a/composer.json b/composer.json index 82daf9a..0c43a7d 100644 --- a/composer.json +++ b/composer.json @@ -19,11 +19,11 @@ ], "require": { "php": ">=8.1", - "squizlabs/php_codesniffer": "^3.9" + "squizlabs/php_codesniffer": "^3.10" }, "require-dev": { - "phpunit/phpunit": "^9.5", - "scrutinizer/ocular": "^1.8.1" + "phpunit/phpunit": "^10.5", + "scrutinizer/ocular": "^1.6" }, "autoload": { "psr-4": { @@ -52,6 +52,10 @@ "test-coverage": "vendor/bin/phpunit --coverage-clover=clover.xml", "test-coverage-local": "php -d xdebug.mode=coverage ./vendor/bin/phpunit --coverage-html=build/coverage", "upload-coverage": "vendor/bin/ocular code-coverage:upload --format=php-clover coverage.xml;", - "phpcs": "vendor/bin/phpcs -p" + "phpcs": "vendor/bin/phpcs -p", + "build": [ + "@test", + "@phpcs" + ] } } diff --git a/phpunit.xml b/phpunit.xml index 39f63f4..9af6d0c 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -3,24 +3,22 @@ ./tests - + src/ - + diff --git a/tests/Core/CodeElement/CodeElementDetectorTest.php b/tests/Core/CodeElement/CodeElementDetectorTest.php index 33b380b..1f5b843 100644 --- a/tests/Core/CodeElement/CodeElementDetectorTest.php +++ b/tests/Core/CodeElement/CodeElementDetectorTest.php @@ -56,6 +56,7 @@ use PHP_CodeSniffer\Config; use PHP_CodeSniffer\Files\LocalFile; use PHP_CodeSniffer\Ruleset; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class CodeElementDetectorTest extends TestCase @@ -63,7 +64,7 @@ class CodeElementDetectorTest extends TestCase /** * @return mixed[][] */ - public function dataDetectFromTokens(): array + public static function dataDetectFromTokens(): array { $dataSets = []; @@ -1320,21 +1321,15 @@ public function dataDetectFromTokens(): array return $dataSets; } - /** - * @dataProvider dataDetectFromTokens - * - * @param bool $givenUseReflection - * @param string $givenPath - * @param FileElement $expected - */ - public function testDetectFromTokens(bool $givenUseReflection, string $givenPath, FileElement $expected): void + #[DataProvider('dataDetectFromTokens')] + public function testDetectFromTokens(bool $givenUseReflection, string $givenFile, FileElement $expected): void { - static::assertFileExists($givenPath); + static::assertFileExists($givenFile); - $givenFile = new LocalFile($givenPath, new Ruleset(new Config()), new Config()); - $givenFile->parse(); + $givenFileObj = new LocalFile($givenFile, new Ruleset(new Config()), new Config()); + $givenFileObj->parse(); - $actual = CodeElementDetector::detectFromTokens($givenFile, $givenUseReflection); + $actual = CodeElementDetector::detectFromTokens($givenFileObj, $givenUseReflection); self::assertEquals($expected, $actual); } diff --git a/tests/Core/DocBlock/DocBlockParserTest.php b/tests/Core/DocBlock/DocBlockParserTest.php index 374b6b5..4560dd1 100644 --- a/tests/Core/DocBlock/DocBlockParserTest.php +++ b/tests/Core/DocBlock/DocBlockParserTest.php @@ -17,6 +17,7 @@ use PHP_CodeSniffer\Exceptions\RuntimeException; use PHP_CodeSniffer\Files\LocalFile; use PHP_CodeSniffer\Ruleset; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class DocBlockParserTest extends TestCase @@ -24,7 +25,7 @@ class DocBlockParserTest extends TestCase /** * @return mixed[][] */ - public function dataDetectFromTokens(): array + public static function dataDetectFromTokens(): array { $dataSets = []; @@ -113,15 +114,10 @@ public function dataDetectFromTokens(): array } /** - * @dataProvider dataDetectFromTokens - * - * @param string $givenPath * @param int[] $givenPointers - * @param DocBlock|null $expectedDocBlock - * @param string|null $expectedException - * * @throws RuntimeException */ + #[DataProvider('dataDetectFromTokens')] public function testDetectFromTokens( string $givenPath, array $givenPointers, @@ -143,7 +139,7 @@ public function testDetectFromTokens( /** * @return mixed[][] */ - public function dataFromRaw(): array + public static function dataFromRaw(): array { $dataSets = []; @@ -249,14 +245,7 @@ public function dataFromRaw(): array return $dataSets; } - /** - * @dataProvider dataFromRaw - * - * @param string $givenRawDocBlock - * @param int $givenStartLine - * @param DocBlock|null $expectedDocBlock - * @param string|null $expectedException - */ + #[DataProvider('dataFromRaw')] public function testFromRaw( string $givenRawDocBlock, int $givenStartLine, diff --git a/tests/Core/Func/FunctionSignatureParserTest.php b/tests/Core/Func/FunctionSignatureParserTest.php index 6ef061c..2a10b48 100644 --- a/tests/Core/Func/FunctionSignatureParserTest.php +++ b/tests/Core/Func/FunctionSignatureParserTest.php @@ -21,6 +21,7 @@ use PHP_CodeSniffer\Exceptions\RuntimeException; use PHP_CodeSniffer\Files\LocalFile; use PHP_CodeSniffer\Ruleset; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class FunctionSignatureParserTest extends TestCase @@ -28,7 +29,7 @@ class FunctionSignatureParserTest extends TestCase /** * @return mixed[][] */ - public function dataFromTokens(): array + public static function dataFromTokens(): array { $dataSets = []; @@ -150,15 +151,9 @@ public function dataFromTokens(): array } /** - * @dataProvider dataFromTokens - * - * @param string $givenPath - * @param int $givenFnPtr - * @param FunctionSignature|null $expectedFun - * @param string|null $expectedException - * * @throws RuntimeException */ + #[DataProvider('dataFromTokens')] public function testFromTokens( string $givenPath, int $givenFnPtr, diff --git a/tests/Core/Type/TypeComparatorTest.php b/tests/Core/Type/TypeComparatorTest.php index 637fbe2..8c7825a 100644 --- a/tests/Core/Type/TypeComparatorTest.php +++ b/tests/Core/Type/TypeComparatorTest.php @@ -2,6 +2,7 @@ namespace Gskema\TypeSniff\Core\Type; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class TypeComparatorTest extends TestCase @@ -9,7 +10,7 @@ class TypeComparatorTest extends TestCase /** * @return string[][] */ - public function dataCompare(): array + public static function dataCompare(): array { // doc_type, fn_type, val_type, wrong_doc, missing_doc return [ @@ -94,15 +95,7 @@ public function dataCompare(): array ]; } - /** - * @dataProvider dataCompare - * - * @param string $givenRawDocType - * @param string $givenRawFnType - * @param string|null $givenRawValueType - * @param string $expectedWrongRawDocTypes - * @param string $expectedMissingRawDocTypes - */ + #[DataProvider('dataCompare')] public function testCompare( string $givenRawDocType, string $givenRawFnType, diff --git a/tests/Core/Type/TypeConverterTest.php b/tests/Core/Type/TypeConverterTest.php index 52efcf6..02ae161 100644 --- a/tests/Core/Type/TypeConverterTest.php +++ b/tests/Core/Type/TypeConverterTest.php @@ -27,6 +27,7 @@ use Gskema\TypeSniff\Core\Type\DocBlock\ThisType; use Gskema\TypeSniff\Core\Type\DocBlock\TrueType; use Gskema\TypeSniff\Core\Type\DocBlock\TypedArrayType; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class TypeConverterTest extends TestCase @@ -34,7 +35,7 @@ class TypeConverterTest extends TestCase /** * @return TypeInterface[][] */ - public function dataToExampleDocType(): array + public static function dataToExampleDocType(): array { return [ [new ArrayType(), new TypedArrayType(new FqcnType('SomeClass'), 1)], @@ -69,12 +70,7 @@ public function dataToExampleDocType(): array ]; } - /** - * @dataProvider dataToExampleDocType - * - * @param TypeInterface $givenFnType - * @param TypeInterface|null $expectedExampleDocType - */ + #[DataProvider('dataToExampleDocType')] public function testToExampleDocType( TypeInterface $givenFnType, ?TypeInterface $expectedExampleDocType, @@ -87,7 +83,7 @@ public function testToExampleDocType( /** * @return TypeInterface[][] */ - public function dataToExampleFnType(): array + public static function dataToExampleFnType(): array { return [ 0 => [ @@ -196,13 +192,7 @@ public function dataToExampleFnType(): array ]; } - /** - * @dataProvider dataToExampleFnType - * - * @param TypeInterface $givenDocType - * @param TypeInterface|null $expectedFnType - * @param bool $givenIsProp - */ + #[DataProvider('dataToExampleFnType')] public function testToExampleFnType( TypeInterface $givenDocType, ?TypeInterface $expectedFnType, diff --git a/tests/Core/Type/TypeFactoryTest.php b/tests/Core/Type/TypeFactoryTest.php index 462344e..7421509 100644 --- a/tests/Core/Type/TypeFactoryTest.php +++ b/tests/Core/Type/TypeFactoryTest.php @@ -29,6 +29,7 @@ use Gskema\TypeSniff\Core\Type\DocBlock\ThisType; use Gskema\TypeSniff\Core\Type\DocBlock\TrueType; use Gskema\TypeSniff\Core\Type\DocBlock\TypedArrayType; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class TypeFactoryTest extends TestCase @@ -36,7 +37,7 @@ class TypeFactoryTest extends TestCase /** * @return mixed[][] */ - public function dataSplit(): array + public static function dataSplit(): array { $dataSets = [ ['int $param1', [['int'], '$param1']], @@ -88,11 +89,9 @@ public function dataSplit(): array } /** - * @dataProvider dataSplit - * - * @param string $givenTagBody * @param mixed[] $expectedSplit */ + #[DataProvider('dataSplit')] public function testSplit( string $givenTagBody, array $expectedSplit, @@ -111,7 +110,7 @@ public static function doSplit(string $tagBody): array /** * @return mixed[][] */ - public function dataFromRawType(): array + public static function dataFromRawType(): array { $dataSets = [ ['array' , new ArrayType()], @@ -284,11 +283,7 @@ public function dataFromRawType(): array return $dataSets; } - /** - * @dataProvider dataFromRawType - * @param string $givenRawType - * @param TypeInterface $expectedType - */ + #[DataProvider('dataFromRawType')] public function testFromRawType(string $givenRawType, TypeInterface $expectedType): void { self::assertEquals($expectedType, TypeFactory::fromRawType($givenRawType)); diff --git a/tests/Core/Type/TypeHelperTest.php b/tests/Core/Type/TypeHelperTest.php index 216a48d..f99613a 100644 --- a/tests/Core/Type/TypeHelperTest.php +++ b/tests/Core/Type/TypeHelperTest.php @@ -5,6 +5,7 @@ use Gskema\TypeSniff\Core\Type\Common\ArrayType; use Gskema\TypeSniff\Core\Type\Common\IntType; use Gskema\TypeSniff\Core\Type\DocBlock\TypedArrayType; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class TypeHelperTest extends TestCase @@ -12,7 +13,7 @@ class TypeHelperTest extends TestCase /** * @return mixed[][] */ - public function dataGetFakeTypedArrayType(): array + public static function dataGetFakeTypedArrayType(): array { return [ [null, null], @@ -22,12 +23,7 @@ public function dataGetFakeTypedArrayType(): array ]; } - /** - * @dataProvider dataGetFakeTypedArrayType - * - * @param TypeInterface|null $givenType - * @param TypeInterface|null $expectedFakeType - */ + #[DataProvider('dataGetFakeTypedArrayType')] public function testGetFakeTypedArrayType(?TypeInterface $givenType, ?TypeInterface $expectedFakeType): void { $actualFakeType = TypeHelper::getFakeTypedArrayType($givenType); diff --git a/tests/Sniffs/CompositeCodeElementSniffTest.php b/tests/Sniffs/CompositeCodeElementSniffTest.php index 9ef9ac6..ac8c3df 100644 --- a/tests/Sniffs/CompositeCodeElementSniffTest.php +++ b/tests/Sniffs/CompositeCodeElementSniffTest.php @@ -5,6 +5,7 @@ use PHP_CodeSniffer\Config; use PHP_CodeSniffer\Files\LocalFile; use PHP_CodeSniffer\Ruleset; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class CompositeCodeElementSniffTest extends TestCase @@ -12,7 +13,7 @@ class CompositeCodeElementSniffTest extends TestCase /** * @return mixed[][] */ - public function dataProcess(): array + public static function dataProcess(): array { $dataSets = []; @@ -569,12 +570,10 @@ public function dataProcess(): array } /** - * @dataProvider dataProcess - * * @param mixed[] $givenConfig - * @param string $givenPath * @param string[] $expectedWarnings */ + #[DataProvider('dataProcess')] public function testProcess( array $givenConfig, string $givenPath, diff --git a/tests/Sniffs/FqcnMethodSniffTest.php b/tests/Sniffs/FqcnMethodSniffTest.php index 13df947..0cd3c96 100644 --- a/tests/Sniffs/FqcnMethodSniffTest.php +++ b/tests/Sniffs/FqcnMethodSniffTest.php @@ -13,6 +13,7 @@ use Gskema\TypeSniff\Core\Type\Common\UndefinedType; use Gskema\TypeSniff\Core\Type\Common\VoidType; use Gskema\TypeSniff\Sniffs\CodeElement\FqcnMethodSniff; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class FqcnMethodSniffTest extends TestCase @@ -20,7 +21,7 @@ class FqcnMethodSniffTest extends TestCase /** * @return mixed[][] */ - public function dataHasUselessDocBlock(): array + public static function dataHasUselessDocBlock(): array { $dataSets = []; @@ -141,12 +142,7 @@ public function dataHasUselessDocBlock(): array return $dataSets; } - /** - * @dataProvider dataHasUselessDocBlock - * - * @param AbstractFqcnMethodElement $givenMethod - * @param bool $expectedResult - */ + #[DataProvider('dataHasUselessDocBlock')] public function testHasUselessDocBlock( AbstractFqcnMethodElement $givenMethod, bool $expectedResult,