Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DX: check fixer's options for wording #7543

Merged
merged 6 commits into from
Dec 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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