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 2 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
12 changes: 11 additions & 1 deletion 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 @@ -464,6 +465,11 @@ protected function lintSource(string $source): ?string
protected static function assertCorrectCasing(string $haystack, string $needle, string $fixerName, string $descriptionType): void
{
$exceptions = [
'PHPDoc' => [
'option:comment_type' => [
'align_multiline_comment' => 2,
],
],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dropped it on local machine to check how the error will look alike if someone would use phpdocs_ option in other fixer.

Outcome is confusing:

1) PhpCsFixer\Tests\Fixer\Phpdoc\AlignMultilineCommentFixerTest::testXxxFixerConfigurationDefinitions
[align_multiline_comment] `PHPDoc` must be in correct casing in option:comment_type.
Failed asserting that 1 is identical to 3.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is confusing in "PHPDoc must be in correct casing in option:comment_type."? It is quite clear to me what is wrong.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was confusing as test was complaining about plural/singular and test failure description was complaining about casing.

not the case anymore with newest state of this PR

'PHPUnit' => [
'description' => [
'ordered_class_elements' => 1,
Expand Down Expand Up @@ -494,7 +500,11 @@ private function getLinter(): LinterInterface
private static function assertValidDescription(string $fixerName, string $descriptionType, string $description): void
{
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::assertSame(
0,
substr_count($description, 'phpdocs') - substr_count($description, '`phpdocs_'), // allow the optio
kubawerlos marked this conversation as resolved.
Show resolved Hide resolved
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::assertFalse(strpos($descriptionType, '``'), sprintf('[%s] The %s must no contain sequential backticks.', $fixerName, $descriptionType));
Expand Down