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
base: master
Are you sure you want to change the base?
feat: support PHPUnit v9.1 naming for some asserts #7997
Conversation
I don't know how to mark it as draft so I closed it, will reopen when done |
@krzysztof-ciszewski I've converted it to a draft, so feel free to push changes and verify with the full CI 🙂. |
There was a problem hiding this 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> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @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> |
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @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> |
@Wirone can you remove the draft now? The pipeline is green 🍾 |
@krzysztof-ciszewski no problem 🙂. FYI, for future contributions: There is also possibility to create PR as draft (dedicated button on PR form). |
@@ -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, [ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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.
if ('assertnotisreadable' === $assertCall['loweredName']) { | ||
$replacement = 'assertIsNotReadable'; | ||
} elseif ('assertnotiswritable' === $assertCall['loweredName']) { | ||
$replacement = 'assertIsNotWritable'; | ||
} elseif ('assertdirectorynotexists' === $assertCall['loweredName']) { | ||
$replacement = 'assertDirectoryDoesNotExist'; | ||
} elseif ('assertfilenotexists' === $assertCall['loweredName']) { | ||
$replacement = 'assertFileDoesNotExist'; | ||
} |
There was a problem hiding this comment.
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.
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