diff --git a/tests/Test/AbstractFixerTestCase.php b/tests/Test/AbstractFixerTestCase.php index 72b9f41c89e..a5333fddfd3 100644 --- a/tests/Test/AbstractFixerTestCase.php +++ b/tests/Test/AbstractFixerTestCase.php @@ -350,6 +350,7 @@ final public function testFixerConfigurationDefinitions(): void foreach ($configurationDefinition->getOptions() as $option) { self::assertInstanceOf(FixerOptionInterface::class, $option); self::assertNotEmpty($option->getDescription()); + self::assertValidDescription($this->fixer->getName(), 'option:'.$option->getName(), $option->getDescription()); self::assertSame( !isset($this->allowedRequiredOptions[$this->fixer->getName()][$option->getName()]), @@ -463,17 +464,9 @@ protected function lintSource(string $source): ?string protected static function assertCorrectCasing(string $haystack, string $needle, string $fixerName, string $descriptionType): void { - $exceptions = [ - 'PHPUnit' => [ - 'description' => [ - 'ordered_class_elements' => 1, - ], - ], - ]; - self::assertSame( substr_count(strtolower($haystack), strtolower($needle)), - substr_count($haystack, $needle) + ($exceptions[$needle][$descriptionType][$fixerName] ?? 0), + substr_count($haystack, $needle), sprintf('[%s] `%s` must be in correct casing in %s.', $fixerName, $needle, $descriptionType) ); } @@ -493,10 +486,17 @@ private function getLinter(): LinterInterface private static function assertValidDescription(string $fixerName, string $descriptionType, string $description): void { + // Description: + // "Option `a` and `b_c` are allowed." + // becomes: + // "Option `_` and `_` are allowed." + // so values in backticks are excluded from check + $descriptionWithExcludedNames = preg_replace('/`([^`]+)`/', '`_`', $description); + self::assertMatchesRegularExpression('/^[A-Z`].+\.$/s', $description, sprintf('[%s] The %s must start with capital letter or a ` and end with dot.', $fixerName, $descriptionType)); - self::assertStringNotContainsString('phpdocs', $description, sprintf('[%s] `PHPDoc` must not be in the plural in %s.', $fixerName, $descriptionType)); - self::assertCorrectCasing($description, 'PHPDoc', $fixerName, $descriptionType); - self::assertCorrectCasing($description, 'PHPUnit', $fixerName, $descriptionType); + self::assertStringNotContainsString('phpdocs', $descriptionWithExcludedNames, sprintf('[%s] `PHPDoc` must not be in the plural in %s.', $fixerName, $descriptionType)); + self::assertCorrectCasing($descriptionWithExcludedNames, 'PHPDoc', $fixerName, $descriptionType); + self::assertCorrectCasing($descriptionWithExcludedNames, 'PHPUnit', $fixerName, $descriptionType); self::assertFalse(strpos($descriptionType, '``'), sprintf('[%s] The %s must no contain sequential backticks.', $fixerName, $descriptionType)); }