Skip to content

Commit

Permalink
DX: check fixer's options for wording (PHP-CS-Fixer#7543)
Browse files Browse the repository at this point in the history
  • Loading branch information
kubawerlos authored and danog committed Feb 2, 2024
1 parent 1b4fdcd commit 62f8dcb
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions tests/Test/AbstractFixerTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()]),
Expand Down Expand Up @@ -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)
);
}
Expand All @@ -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));
}

Expand Down

0 comments on commit 62f8dcb

Please sign in to comment.