| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
@ondrejmirtes here another low hanging fruit :-) |
Sorry, something went wrong.
There was a problem hiding this comment.
A fix and a test for tricky situations with named arguments would be nice here 😊
Sorry, something went wrong.
There was a problem hiding this comment.
The fixer can alter unrelated arguments, mishandle unpacking, skip valid fixes, and suppress existing diagnostics.
Review effort: Balanced
Findings: 1
Adds autofix support for replacing assertSame(..., count(...)) patterns with assertCount(...).
Changes:
| File | Description |
|---|---|
| src/Rules/PHPUnit/AssertSameWithCountRule.php | Implements autofix generation. |
| tests/Rules/PHPUnit/AssertSameWithCountRuleTest.php | Tests fixes and named arguments. |
| tests/Rules/PHPUnit/data/assert-same-count-fixable.php | Provides autofix input cases. |
| tests/Rules/PHPUnit/data/assert-same-count-fixable.php.fixed | Defines expected fixed output. |
| tests/Rules/PHPUnit/data/assert-same-count-named-arguments.php | Covers named-argument cases. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Sorry, something went wrong.
There was a problem hiding this comment.
The fixer can incorrectly rewrite non-actual and unpacked arguments, and its named-argument safeguards are not exercised.
Review effort: Balanced
Findings: 1 · 1
In code that hasn't changed since last review
src/Rules/PHPUnit/AssertSameWithCountRule.php:166
Only the second argument is the counted expression, but this branch currently processes every call-like argument. For example, assertSame(count($expected), count($actual)) is rewritten to assertCount($expected, $actual), changing the expected count; call-like message arguments can also unnecessarily suppress the fix. Restrict this transformation to argument index 1 and add a regression case.
src/Rules/PHPUnit/AssertSameWithCountRule.php:177
An unpacked argument is not equivalent to its underlying expression. For example, count(...$arrays) counts the unpacked array while the generated assertCount(..., $arrays) counts the outer array, so this auto-fix changes behavior. Treat an unpacked count argument as non-fixable.
Sorry, something went wrong.
There was a problem hiding this comment.
The fixer can incorrectly unwrap call expressions outside the actual-value argument, changing assertion semantics.
Review effort: Balanced
Findings: 1 · 1
In code that hasn't changed since last review
src/Rules/PHPUnit/AssertSameWithCountRule.php:166
Only the second ($actual) argument should be unwrapped. As written, every call-like argument is rewritten, so assertSame(count($expected), count($actual)) becomes assertCount($expected, $actual) instead of preserving count($expected) as the expected integer. Restrict this branch to index 1; this also avoids unnecessarily declining fixes when the expected value or message is another kind of call.
Sorry, something went wrong.
There was a problem hiding this comment.
The fixer can rewrite the expected argument incorrectly and omits valid two-argument count() fixes.
Review effort: Balanced
Findings: 1 · 1
Sorry, something went wrong.
There was a problem hiding this comment.
The autofix incorrectly rewrites unpacked count() arguments and can change assertion results.
Review effort: Balanced
Findings: 1
Sorry, something went wrong.
There was a problem hiding this comment.
Safe two-argument count() diagnostics remain non-fixable.
Review effort: Balanced
Findings: None
In code that hasn't changed since last review
src/Rules/PHPUnit/AssertSameWithCountRule.php:171
This rejects every two-argument count() call, although the rule already reports calls such as count($value, COUNT_NORMAL) (and calls whose inferred element type makes recursive mode equivalent). Those diagnostics therefore still have no auto-fix even though dropping the proven-normal mode is semantics-preserving; only malformed calls with more than two arguments need to remain unfixed.
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
closes #249
skip named and splat args for auto-fixing. PHPUnit does not support named arguments for assert*.
see https://github.com/sebastianbergmann/phpunit/blob/bfa72f3d37a2fcb76ec57c87728f3623db06c035/src/Framework/Assert.php#L72-L74