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

feat: support PHPUnit v9.1 naming for some asserts #7997

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

krzysztof-ciszewski
Copy link

@krzysztof-ciszewski krzysztof-ciszewski commented May 8, 2024

Fixes #7968

I assumed $fixMap is static for performance so I tried my best to keep it like that.
Could not keep fixmap static, I don't know if it has impact on performace, not sure how to use benchmark

@krzysztof-ciszewski krzysztof-ciszewski changed the title php-cs-fixer#7968 use new naming for some asserts fixx: use new naming for some asserts May 8, 2024
@krzysztof-ciszewski krzysztof-ciszewski changed the title fixx: use new naming for some asserts fix: use new naming for some asserts May 8, 2024
@krzysztof-ciszewski
Copy link
Author

I don't know how to mark it as draft so I closed it, will reopen when done

@Wirone Wirone reopened this May 8, 2024
@Wirone Wirone marked this pull request as draft May 8, 2024 19:30
@Wirone
Copy link
Member

Wirone commented May 8, 2024

@krzysztof-ciszewski I've converted it to a draft, so feel free to push changes and verify with the full CI 🙂.

@coveralls
Copy link

coveralls commented May 9, 2024

Coverage Status

coverage: 96.119% (+0.001%) from 96.118%
when pulling c5a6d59 on krzysztof-ciszewski:fix-assert-for-phpunit-9-1
into 3117b95 on PHP-CS-Fixer:master.

Copy link
Member

@Wirone Wirone left a comment

Choose a reason for hiding this comment

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

That union with simple array (without shape) causes PHPStan errors.

@@ -625,4 +585,82 @@ private function cloneAndClearTokens(Tokens $tokens, int $start, int $end): arra

return $clone;
}

/**
* @return array|array<string, array{positive: string, negative: false|string, argument_count?: int, swap_arguments?: true}|true>
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @return array|array<string, array{positive: string, negative: false|string, argument_count?: int, swap_arguments?: true}|true>
* @return array<string, array{positive: string, negative: false|string, argument_count?: int, swap_arguments?: true}|true>

Copy link
Author

Choose a reason for hiding this comment

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

I went hardcore mode and defined the array shape

@@ -34,79 +34,9 @@
final class PhpUnitDedicateAssertFixer extends AbstractPhpUnitFixer implements ConfigurableFixerInterface
{
/**
* @var array<string, array{positive: string, negative: false|string, argument_count?: int, swap_arguments?: true}|true>
* @var array|array<string, array{positive: string, negative: false|string, argument_count?: int, swap_arguments?: true}|true>
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @var array|array<string, array{positive: string, negative: false|string, argument_count?: int, swap_arguments?: true}|true>
* @var array<string, array{positive: string, negative: false|string, argument_count?: int, swap_arguments?: true}|true>

@krzysztof-ciszewski
Copy link
Author

@Wirone can you remove the draft now? The pipeline is green 🍾

@Wirone Wirone marked this pull request as ready for review May 9, 2024 15:33
@Wirone
Copy link
Member

Wirone commented May 9, 2024

@krzysztof-ciszewski no problem 🙂. FYI, for future contributions:

image

image

There is also possibility to create PR as draft (dedicated button on PR form).

@Wirone Wirone changed the title fix: use new naming for some asserts feat: support PHPUnit v9.1 naming for some asserts May 9, 2024
@@ -169,6 +171,35 @@ public function configure(array $configuration): void
'str_contains',
]);
}

if (PhpUnitTargetVersion::fulfills($this->configuration['target'], PhpUnitTargetVersion::VERSION_9_1)) {
$this->fixMap = array_merge($this->fixMap, [
Copy link
Member

@keradus keradus May 10, 2024

Choose a reason for hiding this comment

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

instead, keep fixMap static/const and control which functions shall be fixed by this->functions, like for other PHPUnit versions

to rename assertNotIsReadable into assertIsNotReadable, it's role of other rule and not this one.

Choose a reason for hiding this comment

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

Thank you for the advice. I didn't really understand how the rules worked, but now I get it. I refactored it.

'is_readable' => array_merge(
$this->fixMap['is_readable'] ?? [],
[
'negative' => 'assertIsNotReadable',
Copy link
Member

Choose a reason for hiding this comment

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

to rename assertNotIsReadable into assertIsNotReadable, it's role of other rule and not this one.

Comment on lines +727 to +735
if ('assertnotisreadable' === $assertCall['loweredName']) {
$replacement = 'assertIsNotReadable';
} elseif ('assertnotiswritable' === $assertCall['loweredName']) {
$replacement = 'assertIsNotWritable';
} elseif ('assertdirectorynotexists' === $assertCall['loweredName']) {
$replacement = 'assertDirectoryDoesNotExist';
} elseif ('assertfilenotexists' === $assertCall['loweredName']) {
$replacement = 'assertFileDoesNotExist';
}

Choose a reason for hiding this comment

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

Strange that mess-detector prefers this over switch statement, not everything can be refactored to polymorphism, especially string comparison.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PhpUnitDedicateAssertFixer is replacing functions with deprecated/removed method names of PHPUnit v9.1+
4 participants