Repository navigation
Make AssertSameWithCountRule auto-fixable
#259
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
dfd6b09
Make AssertSameWithCountRule auto-fixable
staabm 7110421
skip named args
staabm 7a0377a
skip inner named args
staabm 4eb576f
refactor
staabm ff49176
skip named args for auto-fixing for now
staabm d8c602d
Update AssertSameWithCountRule.php
staabm 61b3061
simplify
staabm 13a5a59
Update AssertSameWithCountRule.php
staabm e560171
we don't expect any fixes for named arguments
staabm c5fbf61
Updated AssertSameWithCountRule to unwrap only the actual-value argum…
staabm 5e889eb
skip unpack
staabm bda4b02
reuse helper
staabm caf2e2a
Update AssertSameWithCountRule.php
staabm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| <?php declare(strict_types = 1); | ||
|
|
||
| namespace ExampleTestCaseFix; | ||
|
|
||
| use const COUNT_RECURSIVE; | ||
|
|
||
| class AssertSameWithCountTestCase extends \PHPUnit\Framework\TestCase | ||
| { | ||
|
|
||
| public function testAssertSameWithCount() | ||
| { | ||
| $this->assertSame(5, count([1, 2, 3])); | ||
| } | ||
|
|
||
| public function testAssertSameWithCountCallsInOtherArguments($expected, $actual, \Countable $countable) | ||
| { | ||
| $this->assertSame(count($expected), count($actual)); | ||
| $this->assertSame(count($expected), count($actual), getMessage()); | ||
| $this->assertSame(count($expected), $countable->count(), getMessage()); | ||
| } | ||
|
|
||
| public function testAssertSameWithCountUnpackedArguments(array $args) | ||
| { | ||
| $this->assertSame(5, count(...$args)); | ||
| } | ||
|
|
||
| public function testAssertSameWithCountRecursive($x) | ||
| { | ||
| $this->assertSame(5, count([1, 2, 3, $x], COUNT_RECURSIVE)); | ||
| } | ||
|
|
||
| public function testAssertSameWithCountMethodForCountableVariableIsNotOK() | ||
| { | ||
| $bar = new \ExampleTestCaseFix\Bar (); | ||
|
|
||
| $this->assertSame(5, $bar->count()); | ||
| } | ||
|
|
||
| public function testAssertSameWithCountMethodForCountablePropertyFetchIsNotOK() | ||
| { | ||
| $foo = new \stdClass(); | ||
| $foo->bar = new Bar (); | ||
|
|
||
| $this->assertSame(5, $foo->bar->count()); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| class Bar implements \Countable { | ||
| public function count(): int | ||
| { | ||
| return 1; | ||
| } | ||
| } |
54 changes: 54 additions & 0 deletions
54
tests/Rules/PHPUnit/data/assert-same-count-fixable.php.fixed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| <?php declare(strict_types = 1); | ||
|
|
||
| namespace ExampleTestCaseFix; | ||
|
|
||
| use const COUNT_RECURSIVE; | ||
|
|
||
| class AssertSameWithCountTestCase extends \PHPUnit\Framework\TestCase | ||
| { | ||
|
|
||
| public function testAssertSameWithCount() | ||
| { | ||
| $this->assertCount(5, [1, 2, 3]); | ||
| } | ||
|
|
||
| public function testAssertSameWithCountCallsInOtherArguments($expected, $actual, \Countable $countable) | ||
| { | ||
| $this->assertCount(count($expected), $actual); | ||
| $this->assertCount(count($expected), $actual, getMessage()); | ||
| $this->assertCount(count($expected), $countable, getMessage()); | ||
| } | ||
|
|
||
| public function testAssertSameWithCountUnpackedArguments(array $args) | ||
| { | ||
| $this->assertSame(5, count(...$args)); | ||
| } | ||
|
|
||
| public function testAssertSameWithCountRecursive($x) | ||
| { | ||
| $this->assertSame(5, count([1, 2, 3, $x], COUNT_RECURSIVE)); | ||
| } | ||
|
|
||
| public function testAssertSameWithCountMethodForCountableVariableIsNotOK() | ||
| { | ||
| $bar = new \ExampleTestCaseFix\Bar (); | ||
|
|
||
| $this->assertCount(5, $bar); | ||
| } | ||
|
|
||
| public function testAssertSameWithCountMethodForCountablePropertyFetchIsNotOK() | ||
| { | ||
| $foo = new \stdClass(); | ||
| $foo->bar = new Bar (); | ||
|
|
||
| $this->assertCount(5, $foo->bar); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| class Bar implements \Countable { | ||
| public function count(): int | ||
| { | ||
| return 1; | ||
| } | ||
| } |
30 changes: 30 additions & 0 deletions
30
tests/Rules/PHPUnit/data/assert-same-count-named-arguments.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| <?php // lint >= 8.0 | ||
|
|
||
| namespace ExampleTestCaseFixNamedArguments; | ||
|
|
||
| use function count; | ||
|
|
||
| class AssertSameWithCountTestCase extends \PHPUnit\Framework\TestCase | ||
| { | ||
|
|
||
| public function skipNamedArguments(Bar $bar): void | ||
| { | ||
| $this->assertSame(expected: 5, actual: count([1, 2, 3]), message: 'message'); | ||
| $this->assertSame(message: 'message', actual: count(value: [1, 2, 3]), expected: 5); | ||
| self::assertSame(actual: $bar->count(), expected: 5); | ||
| $this->assertSame(5, actual: count([1, 2, 3]), message: 'message'); | ||
|
|
||
| $this->assertSame(5, count(value: [1, 2, 3]), 'message'); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| class Bar implements \Countable | ||
| { | ||
|
|
||
| public function count(): int | ||
| { | ||
| return 1; | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.