From d9b11fd45e46f42b38559cfbc4e6d2ccf566537c Mon Sep 17 00:00:00 2001 From: Ben Ramsey Date: Tue, 16 Apr 2024 23:15:28 -0500 Subject: [PATCH] chore: upgrade packages; remove Psalm --- .gitattributes | 2 -- .github/workflows/continuous-integration.yml | 34 ++----------------- CONTRIBUTING.md | 5 ++- README.md | 1 - composer.json | 18 ++++------ phpunit.xml.dist | 7 ++-- psalm.xml | 18 ---------- src/CaptainHook/Input.php | 1 - src/CaptainHook/PrepareConventionalCommit.php | 2 +- .../ValidateConventionalCommit.php | 2 +- .../Configuration/Configuration.php | 4 +-- .../Configuration/DefaultConfiguration.php | 9 +++-- .../Configuration/FinderTool.php | 1 - .../Console/Command/PrepareCommand.php | 21 ++---------- .../Console/Command/ValidateCommand.php | 1 - src/ConventionalCommits/Parser.php | 16 +++------ .../DefaultConfigurationTest.php | 2 +- .../Configuration/FinderToolTest.php | 2 +- .../Converter/LetterCaseConverterTest.php | 2 +- .../Message/DescriptionTest.php | 6 ++-- .../Message/FooterTest.php | 16 ++++----- .../Message/NounTestCase.php | 6 ++-- tests/ConventionalCommits/MessageTest.php | 4 +-- tests/ConventionalCommits/ParserTest.php | 4 +-- .../Validator/EndMarkValidatorTest.php | 2 +- .../Validator/LetterCaseValidatorTest.php | 2 +- .../RequiredFootersValidatorTest.php | 13 ++++--- .../Validator/ScopeValidatorTest.php | 10 ++++-- .../Validator/TypeValidatorTest.php | 10 ++++-- tests/SnapshotsTool.php | 6 ++-- tests/WindowsSafeTextDriver.php | 26 +++++++------- 31 files changed, 89 insertions(+), 164 deletions(-) delete mode 100644 psalm.xml diff --git a/.gitattributes b/.gitattributes index e259012..4eee60a 100644 --- a/.gitattributes +++ b/.gitattributes @@ -14,8 +14,6 @@ /phpcs.xml.dist export-ignore /phpstan.neon.dist export-ignore /phpunit.xml.dist export-ignore -/psalm-baseline.xml export-ignore -/psalm.xml export-ignore /resources/ export-ignore /SECURITY.md export-ignore /tests/ export-ignore diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 9ab0dff..e72dbfe 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -66,36 +66,6 @@ jobs: shell: "bash" run: "composer dev:analyze:phpstan" - - name: "Statically analyze code (Psalm)" - shell: "bash" - run: "composer dev:analyze:psalm -- --shepherd" - - security-analysis: - name: "Security analysis" - needs: ["coding-standards", "static-analysis"] - runs-on: "ubuntu-latest" - steps: - - name: "Checkout repository" - uses: "actions/checkout@v3.3.0" - - - name: "Install PHP" - uses: "shivammathur/setup-php@2.23.0" - with: - php-version: "latest" - coverage: "none" - - - name: "Install dependencies (Composer)" - uses: "ramsey/composer-install@2.2.0" - - - name: "Analyze security of code (Psalm)" - shell: "bash" - run: "./vendor/bin/psalm --taint-analysis --report=build/logs/psalm.sarif" - - - name: "Upload security analysis results to GitHub" - uses: "github/codeql-action/upload-sarif@v2" - with: - sarif_file: "build/logs/psalm.sarif" - code-coverage: name: "Code coverage" needs: ["coding-standards", "static-analysis"] @@ -123,7 +93,7 @@ jobs: unit-tests: name: "Unit tests" - needs: ["code-coverage", "security-analysis"] + needs: ["code-coverage"] runs-on: ${{ matrix.operating-system }} strategy: @@ -172,7 +142,7 @@ jobs: functional-tests: name: "Functional tests" - needs: ["code-coverage", "security-analysis"] + needs: ["code-coverage"] runs-on: "ubuntu-latest" strategy: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3d0684c..bb3adbb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -134,9 +134,8 @@ composer dev:lint:fix ### Static Analysis -This project uses a combination of [PHPStan](https://github.com/phpstan/phpstan) -and [Psalm](https://github.com/vimeo/psalm) to provide static analysis of PHP -code. +This project uses [PHPStan](https://github.com/phpstan/phpstan) to provide +static analysis of PHP code. CaptainHook will run static analysis checks before committing. diff --git a/README.md b/README.md index 53bc949..2086a3d 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,6 @@ Read License Build Status Codecov Code Coverage - Psalm Type Coverage

## About diff --git a/composer.json b/composer.json index da2d351..1876f47 100644 --- a/composer.json +++ b/composer.json @@ -42,17 +42,14 @@ "phpstan/phpstan": "^1.10", "phpstan/phpstan-mockery": "^1.1", "phpstan/phpstan-phpunit": "^1.3", - "phpunit/phpunit": "^9.5", - "psalm/plugin-mockery": "^1.1", - "psalm/plugin-phpunit": "^0.18.4", + "phpunit/phpunit": "^10.1", "ramsey/coding-standard": "^2.2", "ramsey/composer-repl": "^1.4", "roave/security-advisories": "dev-latest", "sebastianfeldmann/cli": "^3.4", "sebastianfeldmann/git": "^3.8", - "spatie/phpunit-snapshot-assertions": "^4.2", - "symfony/process": "^6.0", - "vimeo/psalm": "^5.8" + "spatie/phpunit-snapshot-assertions": "^5.1", + "symfony/process": "^6.0 || ^7.0" }, "suggest": { "captainhook/captainhook": "Manage your project's Git hooks with CaptainHook, and use ramsey/conventional-commits in your commit-msg and prepare-commit-msg hooks." @@ -75,10 +72,10 @@ ], "config": { "allow-plugins": { - "phpstan/extension-installer": true, + "captainhook/plugin-composer": true, "dealerdirect/phpcodesniffer-composer-installer": true, "ergebnis/composer-normalize": true, - "captainhook/plugin-composer": true, + "phpstan/extension-installer": true, "ramsey/composer-repl": true }, "sort-packages": true @@ -96,11 +93,9 @@ }, "scripts": { "dev:analyze": [ - "@dev:analyze:phpstan", - "@dev:analyze:psalm" + "@dev:analyze:phpstan" ], "dev:analyze:phpstan": "phpstan analyse --ansi --memory-limit 256M", - "dev:analyze:psalm": "psalm", "dev:build:clean": "git clean -fX build/", "dev:lint": [ "@dev:lint:syntax", @@ -124,7 +119,6 @@ "scripts-descriptions": { "dev:analyze": "Runs all static analysis checks.", "dev:analyze:phpstan": "Runs the PHPStan static analyzer.", - "dev:analyze:psalm": "Runs the Psalm static analyzer.", "dev:build:clean": "Cleans the build/ directory.", "dev:lint": "Runs all linting checks.", "dev:lint:fix": "Auto-fixes coding standards issues, if possible.", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index e46ab59..d8a7f08 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -2,9 +2,8 @@ + cacheDirectory="./build/cache/phpunit"> @@ -12,11 +11,11 @@ - + ./src - + diff --git a/psalm.xml b/psalm.xml deleted file mode 100644 index 14f84f3..0000000 --- a/psalm.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - diff --git a/src/CaptainHook/Input.php b/src/CaptainHook/Input.php index c61752e..a1965df 100644 --- a/src/CaptainHook/Input.php +++ b/src/CaptainHook/Input.php @@ -39,7 +39,6 @@ public function __construct(IO $captainHookIO) $definition = new InputDefinition(); /** - * @psalm-suppress UnnecessaryVarAnnotation * @var string $key */ foreach (array_keys($captainHookIO->getArguments()) as $key) { diff --git a/src/CaptainHook/PrepareConventionalCommit.php b/src/CaptainHook/PrepareConventionalCommit.php index 0908ba3..7a20f76 100644 --- a/src/CaptainHook/PrepareConventionalCommit.php +++ b/src/CaptainHook/PrepareConventionalCommit.php @@ -41,7 +41,7 @@ * During the prepare-commit-msg Git hook, this prompts the user for input and * builds a valid Conventional Commits commit message * - * @psalm-import-type ConfigurationOptionsType from Configuration + * @phpstan-import-type ConfigurationOptionsType from Configuration */ class PrepareConventionalCommit implements Action, Constrained { diff --git a/src/CaptainHook/ValidateConventionalCommit.php b/src/CaptainHook/ValidateConventionalCommit.php index 7eba570..28f5543 100644 --- a/src/CaptainHook/ValidateConventionalCommit.php +++ b/src/CaptainHook/ValidateConventionalCommit.php @@ -41,7 +41,7 @@ * During the commit-msg Git hook, this validates the commit message according * to the Conventional Commits specification * - * @psalm-import-type ConfigurationOptionsType from Configuration + * @phpstan-import-type ConfigurationOptionsType from Configuration */ class ValidateConventionalCommit implements Action, Constrained { diff --git a/src/ConventionalCommits/Configuration/Configuration.php b/src/ConventionalCommits/Configuration/Configuration.php index 37359df..df16185 100644 --- a/src/ConventionalCommits/Configuration/Configuration.php +++ b/src/ConventionalCommits/Configuration/Configuration.php @@ -29,14 +29,14 @@ * A configuration provides additional rules on top of the Conventional * Commits specification * - * @psalm-type ConfigurationOptionsType = array{typeCase?: string | null, types?: string[], scopeCase?: string | null, scopeRequired?: bool, scopes?: string[], descriptionCase?: string | null, descriptionEndMark?: string | null, bodyRequired?: bool, bodyWrapWidth?: int | null, requiredFooters?: string[]} + * @phpstan-type ConfigurationOptionsType array{typeCase?: string | null, types?: string[], scopeCase?: string | null, scopeRequired?: bool, scopes?: string[], descriptionCase?: string | null, descriptionEndMark?: string | null, bodyRequired?: bool, bodyWrapWidth?: int | null, requiredFooters?: string[]} */ interface Configuration extends JsonSerializable { /** * Returns the configuration as an array * - * @psalm-return ConfigurationOptionsType + * @return ConfigurationOptionsType */ public function toArray(): array; diff --git a/src/ConventionalCommits/Configuration/DefaultConfiguration.php b/src/ConventionalCommits/Configuration/DefaultConfiguration.php index a7e83f4..5515eac 100644 --- a/src/ConventionalCommits/Configuration/DefaultConfiguration.php +++ b/src/ConventionalCommits/Configuration/DefaultConfiguration.php @@ -41,7 +41,7 @@ /** * Default configuration for Conventional Commits commit messages * - * @psalm-import-type ConfigurationOptionsType from Configuration + * @phpstan-import-type ConfigurationOptionsType from Configuration */ class DefaultConfiguration implements Configuration { @@ -70,7 +70,7 @@ class DefaultConfiguration implements Configuration private ?MessageValidator $messageValidator = null; /** - * @psalm-param ConfigurationOptionsType $options + * @param ConfigurationOptionsType $options */ public function __construct(array $options = []) { @@ -110,8 +110,7 @@ public function toArray(): array } /** - * @psalm-return ConfigurationOptionsType - * @psalm-suppress UndefinedAttributeClass + * @return ConfigurationOptionsType */ #[ReturnTypeWillChange] public function jsonSerialize() @@ -214,7 +213,7 @@ public function getMessageValidator(): MessageValidator } /** - * @psalm-param ConfigurationOptionsType $options + * @param ConfigurationOptionsType $options */ private function caseIfValid(array $options, string $parameter): ?string { diff --git a/src/ConventionalCommits/Configuration/FinderTool.php b/src/ConventionalCommits/Configuration/FinderTool.php index bc67c26..20b5e8f 100644 --- a/src/ConventionalCommits/Configuration/FinderTool.php +++ b/src/ConventionalCommits/Configuration/FinderTool.php @@ -195,7 +195,6 @@ private function validateConfig(object $config): bool ); } - /** @psalm-suppress MixedArgumentTypeCoercion */ throw new InvalidValue($messages); } diff --git a/src/ConventionalCommits/Console/Command/PrepareCommand.php b/src/ConventionalCommits/Console/Command/PrepareCommand.php index 9bf6d44..1dc21f4 100644 --- a/src/ConventionalCommits/Console/Command/PrepareCommand.php +++ b/src/ConventionalCommits/Console/Command/PrepareCommand.php @@ -118,25 +118,21 @@ protected function doExecute(InputInterface $input, OutputInterface $output): in private function askQuestions(SymfonyStyle $console): Message { /** - * @psalm-suppress ReservedWord * @var Type $type */ $type = $console->askQuestion(new TypeQuestion($this->getConfiguration())); /** - * @psalm-suppress ReservedWord * @var Scope|null $scope */ $scope = $console->askQuestion(new ScopeQuestion($this->getConfiguration())); /** - * @psalm-suppress ReservedWord * @var Description $description */ $description = $console->askQuestion(new DescriptionQuestion($this->getConfiguration())); /** - * @psalm-suppress ReservedWord * @var Body|null $body */ $body = $console->askQuestion(new BodyQuestion($this->getConfiguration())); @@ -171,13 +167,8 @@ private function askFooterQuestions(SymfonyStyle $console): array { $footers = []; - /** - * @psalm-suppress RedundantCondition - * @psalm-suppress ReservedWord - */ if ($console->askQuestion(new HasBreakingChangesQuestion())) { /** - * @psalm-suppress ReservedWord * @var Footer $breakingChanges */ $breakingChanges = $console->askQuestion(new DescribeBreakingChangesQuestion()); @@ -203,9 +194,9 @@ private function askFooterQuestions(SymfonyStyle $console): array } /** - * @return Footer[] + * @param Closure(string):Question $valueQuestionCallback * - * @psalm-param Closure(string):Question $valueQuestionCallback + * @return Footer[] */ private function askFooterQuestionSection( SymfonyStyle $console, @@ -214,10 +205,6 @@ private function askFooterQuestionSection( Closure $valueQuestionCallback, bool $isRequired = false, ): array { - /** - * @psalm-suppress ReservedWord - * @psalm-suppress TypeDoesNotContainType - */ if (!$isRequired && !$console->askQuestion($decisionPathQuestion)) { return []; } @@ -236,7 +223,7 @@ private function askFooterQuestionSection( } /** - * @psalm-param Closure(string):Question $valueQuestionCallback + * @param Closure(string):Question $valueQuestionCallback */ private function askFooterQuestion( SymfonyStyle $console, @@ -244,7 +231,6 @@ private function askFooterQuestion( Closure $valueQuestionCallback, ): ?Footer { /** - * @psalm-suppress ReservedWord * @var string|null $token */ $token = $console->askQuestion($tokenQuestion); @@ -254,7 +240,6 @@ private function askFooterQuestion( } /** - * @psalm-suppress ReservedWord * @var Footer|null $footer */ $footer = $console->askQuestion($valueQuestionCallback($token)); diff --git a/src/ConventionalCommits/Console/Command/ValidateCommand.php b/src/ConventionalCommits/Console/Command/ValidateCommand.php index c6c6386..766ad44 100644 --- a/src/ConventionalCommits/Console/Command/ValidateCommand.php +++ b/src/ConventionalCommits/Console/Command/ValidateCommand.php @@ -76,7 +76,6 @@ protected function doExecute(InputInterface $input, OutputInterface $output): in if ($message === null) { $console->title('Validate Commit Message'); /** - * @psalm-suppress ReservedWord * @var string|null $message */ $message = $console->askQuestion(new MessageQuestion($this->getConfiguration())); diff --git a/src/ConventionalCommits/Parser.php b/src/ConventionalCommits/Parser.php index e225873..91d367a 100644 --- a/src/ConventionalCommits/Parser.php +++ b/src/ConventionalCommits/Parser.php @@ -110,21 +110,13 @@ private function parseFooter(string $footer): array return []; } - /** - * Psalm needs this because there's no way to define the array structure - * above the preg_match_all() statement where $matches is instantiated. - * - * @var array{token: list, separator: list, value: list} $footerParams - */ - $footerParams = $matches; - $footers = []; - for ($i = 0; $i < count($footerParams['token']); $i++) { + for ($i = 0; $i < count($matches['token']); $i++) { $footers[] = new Footer( - $footerParams['token'][$i], - $footerParams['value'][$i], - $footerParams['separator'][$i], + $matches['token'][$i], + $matches['value'][$i], + $matches['separator'][$i], ); } diff --git a/tests/ConventionalCommits/Configuration/DefaultConfigurationTest.php b/tests/ConventionalCommits/Configuration/DefaultConfigurationTest.php index 674e02a..bb67176 100644 --- a/tests/ConventionalCommits/Configuration/DefaultConfigurationTest.php +++ b/tests/ConventionalCommits/Configuration/DefaultConfigurationTest.php @@ -120,7 +120,7 @@ public function testThrowsOnInvalidData(array $options, string $expectedMessage) /** * @return array */ - public function provideInvalidData(): array + public static function provideInvalidData(): array { return [ [ diff --git a/tests/ConventionalCommits/Configuration/FinderToolTest.php b/tests/ConventionalCommits/Configuration/FinderToolTest.php index 4ddc410..e0b47ff 100644 --- a/tests/ConventionalCommits/Configuration/FinderToolTest.php +++ b/tests/ConventionalCommits/Configuration/FinderToolTest.php @@ -66,7 +66,7 @@ public function testFindConfigurationReturnsConfigurationForPassedArray(array $o /** * @return array */ - public function provideOptions(): array + public static function provideOptions(): array { return [ [ diff --git a/tests/ConventionalCommits/Converter/LetterCaseConverterTest.php b/tests/ConventionalCommits/Converter/LetterCaseConverterTest.php index 61e5815..9e05618 100644 --- a/tests/ConventionalCommits/Converter/LetterCaseConverterTest.php +++ b/tests/ConventionalCommits/Converter/LetterCaseConverterTest.php @@ -35,7 +35,7 @@ public function testConvert(?string $case, string $testValue, string $expectedVa /** * @return array */ - public function provideConversionTestValues(): array + public static function provideConversionTestValues(): array { return [ [ diff --git a/tests/ConventionalCommits/Message/DescriptionTest.php b/tests/ConventionalCommits/Message/DescriptionTest.php index 2a9881e..add2b24 100644 --- a/tests/ConventionalCommits/Message/DescriptionTest.php +++ b/tests/ConventionalCommits/Message/DescriptionTest.php @@ -19,7 +19,7 @@ class DescriptionTest extends TestCase /** * @return array */ - public function provideInvalidDescription(): array + public static function provideInvalidDescription(): array { return [ ['invalidDescription' => "foo\tbar"], @@ -32,7 +32,7 @@ public function provideInvalidDescription(): array /** * @return array */ - public function provideValidDescription(): array + public static function provideValidDescription(): array { return [ ['validDescription' => 'this is a valid description'], @@ -87,7 +87,7 @@ public function testValidatorsWithDescription(string $description, bool $expectF /** * @return array */ - public function provideDescriptionsForValidation(): array + public static function provideDescriptionsForValidation(): array { return [ ['description' => 'this is a valid description.', 'expectFailure' => false], diff --git a/tests/ConventionalCommits/Message/FooterTest.php b/tests/ConventionalCommits/Message/FooterTest.php index c66c590..d17e3b6 100644 --- a/tests/ConventionalCommits/Message/FooterTest.php +++ b/tests/ConventionalCommits/Message/FooterTest.php @@ -18,7 +18,7 @@ class FooterTest extends TestCase /** * @return array */ - public function provideInvalidToken(): array + public static function provideInvalidToken(): array { return [ ['invalidToken' => 'foo bar'], @@ -45,7 +45,7 @@ public function provideInvalidToken(): array /** * @return array */ - public function provideValidToken(): array + public static function provideValidToken(): array { return [ ['validToken' => 'foobar'], @@ -65,7 +65,7 @@ public function provideValidToken(): array /** * @return array */ - public function provideInvalidValue(): array + public static function provideInvalidValue(): array { return [ ['invalidValue' => 'BREAKING CHANGE: a footer within a value'], @@ -83,7 +83,7 @@ public function provideInvalidValue(): array /** * @return array */ - public function provideValidValue(): array + public static function provideValidValue(): array { return [ ['validValue' => 'this value is a BREAKING CHANGE: kind of value'], @@ -100,7 +100,7 @@ public function provideValidValue(): array /** * @return array */ - public function provideInvalidSeparator(): array + public static function provideInvalidSeparator(): array { return [ ['invalidSeparator' => ';'], @@ -114,7 +114,7 @@ public function provideInvalidSeparator(): array /** * @return array */ - public function provideValidSeparator(): array + public static function provideValidSeparator(): array { return [ ['validSeparator' => ': '], @@ -125,7 +125,7 @@ public function provideValidSeparator(): array /** * @return array */ - public function provideBreakingChangeToken(): array + public static function provideBreakingChangeToken(): array { return [ ['breakingChangeToken' => 'BREAKING CHANGE'], @@ -264,7 +264,7 @@ public function testValidatorsWithFooter(string $token, bool $expectFailure): vo /** * @return array */ - public function provideTokensForValidation(): array + public static function provideTokensForValidation(): array { return [ ['token' => 'Footer-Test', 'expectFailure' => false], diff --git a/tests/ConventionalCommits/Message/NounTestCase.php b/tests/ConventionalCommits/Message/NounTestCase.php index f8d04be..fa8cae7 100644 --- a/tests/ConventionalCommits/Message/NounTestCase.php +++ b/tests/ConventionalCommits/Message/NounTestCase.php @@ -30,7 +30,7 @@ abstract protected function getClassName(): string; /** * @return array */ - public function provideInvalidNoun(): array + public static function provideInvalidNoun(): array { return [ ['invalidNoun' => 'foo bar'], @@ -55,7 +55,7 @@ public function provideInvalidNoun(): array /** * @return array */ - public function provideValidNoun(): array + public static function provideValidNoun(): array { return [ ['validNoun' => 'foobar'], @@ -146,7 +146,7 @@ public function testValidatorsWithNoun(string $noun, bool $expectFailure): void /** * @return array */ - public function provideNounsForValidation(): array + public static function provideNounsForValidation(): array { return [ ['noun' => 'Foo-Bar', 'expectFailure' => true], diff --git a/tests/ConventionalCommits/MessageTest.php b/tests/ConventionalCommits/MessageTest.php index 0506152..1d39256 100644 --- a/tests/ConventionalCommits/MessageTest.php +++ b/tests/ConventionalCommits/MessageTest.php @@ -63,7 +63,7 @@ public function testScope(): void public function testBody(): void { - $bodyTest = new BodyTest(); + $bodyTest = new BodyTest(BodyTest::class); $expectedMessage = 'feat: implement awesome thing' . PHP_EOL . PHP_EOL . $bodyTest->getExpectedBody() . PHP_EOL; @@ -133,7 +133,7 @@ public function testWithBreakingChange(): void public function testToStringIncludesEverything(): void { - $bodyTest = new BodyTest(); + $bodyTest = new BodyTest(BodyTest::class); $expectedMessage = 'feat(my-scope)!: implement awesome thing' . PHP_EOL . PHP_EOL . $bodyTest->getExpectedBody() . PHP_EOL . PHP_EOL diff --git a/tests/ConventionalCommits/ParserTest.php b/tests/ConventionalCommits/ParserTest.php index cddf304..adb5b90 100644 --- a/tests/ConventionalCommits/ParserTest.php +++ b/tests/ConventionalCommits/ParserTest.php @@ -23,7 +23,7 @@ class ParserTest extends TestCase /** * @return array */ - public function provideRawCommitMessage(): array + public static function provideRawCommitMessage(): array { return [ 'a basic commit' => [ @@ -69,7 +69,7 @@ public function testParserAccuratelyParsesCommitMessages(string $rawMessageFile) /** * @return array */ - public function provideInvalidCommitMessage(): array + public static function provideInvalidCommitMessage(): array { return [ ['invalidMessageFile' => (string) realpath(__DIR__ . '/commit-messages/invalid-commit-message-00.txt')], diff --git a/tests/ConventionalCommits/Validator/EndMarkValidatorTest.php b/tests/ConventionalCommits/Validator/EndMarkValidatorTest.php index d38c872..fe22df6 100644 --- a/tests/ConventionalCommits/Validator/EndMarkValidatorTest.php +++ b/tests/ConventionalCommits/Validator/EndMarkValidatorTest.php @@ -46,7 +46,7 @@ public function testIsValidOrException(?string $endMark, string $testValue, bool /** * @return array */ - public function provideTestValues(): array + public static function provideTestValues(): array { return [ [ diff --git a/tests/ConventionalCommits/Validator/LetterCaseValidatorTest.php b/tests/ConventionalCommits/Validator/LetterCaseValidatorTest.php index feceb9d..9cc5492 100644 --- a/tests/ConventionalCommits/Validator/LetterCaseValidatorTest.php +++ b/tests/ConventionalCommits/Validator/LetterCaseValidatorTest.php @@ -44,7 +44,7 @@ public function testIsValidOrException(string $case, string $testValue, bool $ex /** * @return array */ - public function provideTestValues(): array + public static function provideTestValues(): array { return [ [ diff --git a/tests/ConventionalCommits/Validator/RequiredFootersValidatorTest.php b/tests/ConventionalCommits/Validator/RequiredFootersValidatorTest.php index 4147909..59feb7c 100644 --- a/tests/ConventionalCommits/Validator/RequiredFootersValidatorTest.php +++ b/tests/ConventionalCommits/Validator/RequiredFootersValidatorTest.php @@ -19,8 +19,12 @@ class RequiredFootersValidatorTest extends TestCase * * @dataProvider provideTestValues */ - public function testIsValid(array $testValue, bool $expectedResult, array $options = []): void - { + public function testIsValid( + array $testValue, + bool $expectedResult, + array $options = [], + string $expectedMessage = '', + ): void { $validator = new RequiredFootersValidator(); if ($options) { @@ -41,6 +45,7 @@ public function testIsValidOrException( bool $expectedResult, array $options = [], string $expectedError = '', + string $expectedMessage = '', ): void { $validator = new RequiredFootersValidator(); @@ -59,7 +64,7 @@ public function testIsValidOrException( /** * @return array */ - public function provideTestValues(): array + public static function provideTestValues(): array { return [ [ @@ -148,7 +153,7 @@ public function testThrowsWhenValueIsInvalid($testValue): void /** * @return array */ - public function provideInvalidValues(): array + public static function provideInvalidValues(): array { return [ [ diff --git a/tests/ConventionalCommits/Validator/ScopeValidatorTest.php b/tests/ConventionalCommits/Validator/ScopeValidatorTest.php index 2008884..49b4b65 100644 --- a/tests/ConventionalCommits/Validator/ScopeValidatorTest.php +++ b/tests/ConventionalCommits/Validator/ScopeValidatorTest.php @@ -16,8 +16,12 @@ class ScopeValidatorTest extends TestCase * * @dataProvider provideScopeTestValues */ - public function testIsValid(string $testValue, bool $expectedResult, array $options = []): void - { + public function testIsValid( + string $testValue, + bool $expectedResult, + array $options = [], + string $expectedError = '', + ): void { $validator = new ScopeValidator(); if ($options) { @@ -55,7 +59,7 @@ public function testIsValidOrException( /** * @return array */ - public function provideScopeTestValues(): array + public static function provideScopeTestValues(): array { $options = ['scopes' => ['FoO', 'baR', 'Baz']]; diff --git a/tests/ConventionalCommits/Validator/TypeValidatorTest.php b/tests/ConventionalCommits/Validator/TypeValidatorTest.php index b8076aa..7c99e55 100644 --- a/tests/ConventionalCommits/Validator/TypeValidatorTest.php +++ b/tests/ConventionalCommits/Validator/TypeValidatorTest.php @@ -16,8 +16,12 @@ class TypeValidatorTest extends TestCase * * @dataProvider provideTypeTestValues */ - public function testIsValid(string $testValue, bool $expectedResult, array $options = []): void - { + public function testIsValid( + string $testValue, + bool $expectedResult, + array $options = [], + string $expectedError = '', + ): void { $validator = new TypeValidator(); if ($options) { @@ -55,7 +59,7 @@ public function testIsValidOrException( /** * @return array */ - public function provideTypeTestValues(): array + public static function provideTypeTestValues(): array { $options = ['types' => ['FoO', 'baR', 'Baz']]; diff --git a/tests/SnapshotsTool.php b/tests/SnapshotsTool.php index 6d3f5f8..f024731 100644 --- a/tests/SnapshotsTool.php +++ b/tests/SnapshotsTool.php @@ -8,7 +8,7 @@ use Spatie\Snapshots\MatchesSnapshots; use function preg_replace; -use function strpos; +use function str_starts_with; use const PHP_OS; @@ -19,13 +19,13 @@ trait SnapshotsTool protected function getSnapshotId(): string { $suffix = ''; - if (strpos(PHP_OS, 'WIN') === 0) { + if (str_starts_with(PHP_OS, 'WIN')) { $suffix = '__WIN'; } $snapshotId = (new ReflectionClass($this))->getShortName() . '__' - . $this->getName() + . $this->nameWithDataSet() . '__' . $this->snapshotIncrementor . $suffix; diff --git a/tests/WindowsSafeTextDriver.php b/tests/WindowsSafeTextDriver.php index 3ec779b..10f9b1b 100644 --- a/tests/WindowsSafeTextDriver.php +++ b/tests/WindowsSafeTextDriver.php @@ -4,9 +4,11 @@ namespace Ramsey\Test; +use LogicException; use PHPUnit\Framework\Assert; use Spatie\Snapshots\Driver; +use function is_string; use function preg_replace; /** @@ -15,16 +17,14 @@ */ class WindowsSafeTextDriver implements Driver { - /** - * @inheritDoc - */ - public function serialize($data): string + public function serialize(mixed $data): string { - /** @var string $stringData */ - $stringData = $data; + if (!is_string($data)) { + throw new LogicException('Data must be a string'); + } // Save snapshot only with lf line endings. - return (string) preg_replace('/\r\n/', "\n", $stringData); + return (string) preg_replace('/\r\n/', "\n", $data); } public function extension(): string @@ -32,17 +32,15 @@ public function extension(): string return 'txt'; } - /** - * @inheritDoc - */ - public function match($expected, $actual): void + public function match(mixed $expected, mixed $actual): void { - /** @var string $stringExpected */ - $stringExpected = $expected; + if (!is_string($expected)) { + throw new LogicException('Expected must be a string'); + } // Make sure the expected string has lf line endings, so we can // compare accurately. - $expected = (string) preg_replace('/\r\n/', "\n", $stringExpected); + $expected = (string) preg_replace('/\r\n/', "\n", $expected); Assert::assertEquals($expected, $this->serialize($actual)); }