-
-
Notifications
You must be signed in to change notification settings - Fork 6
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
Compare class-names case insensitive #42
Closed
Closed
Changes from all commits
Commits
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
There are no files selected for viewing
This file contains 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 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,63 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace TomasVotruba\ClassLeak\Tests\Filtering; | ||
|
||
use Iterator; | ||
use TomasVotruba\ClassLeak\Filtering\PossiblyUnusedClassesFilter; | ||
use TomasVotruba\ClassLeak\Tests\AbstractTestCase; | ||
use TomasVotruba\ClassLeak\ValueObject\FileWithClass; | ||
|
||
final class PossiblyUnusedClassesFilterTest extends AbstractTestCase | ||
{ | ||
/** | ||
* @param FileWithClass[] $filesWithClasses | ||
* @param string[] $usedClassNames | ||
* @param string[] $typesToSkip | ||
* @param string[] $suffixesToSkip | ||
* @param string[] $attributesToSkip | ||
* | ||
* @dataProvider provideData | ||
*/ | ||
public function testFilter( | ||
array $expectedResult, | ||
array $filesWithClasses, | ||
array $usedClassNames, | ||
array $typesToSkip, | ||
array $suffixesToSkip, | ||
array $attributesToSkip | ||
): void | ||
{ | ||
$possiblyUnusedClassesFilter = new PossiblyUnusedClassesFilter(); | ||
$this->assertSame($expectedResult, $possiblyUnusedClassesFilter->filter( | ||
$filesWithClasses, | ||
$usedClassNames, | ||
$typesToSkip, | ||
$suffixesToSkip, | ||
$attributesToSkip | ||
)); | ||
} | ||
|
||
public static function provideData(): Iterator | ||
{ | ||
yield [ // test case-insensitive class name | ||
[], | ||
[new FileWithClass('foo.php', 'Bar', false, [])], | ||
['BAR'], | ||
[], | ||
[], | ||
[] | ||
]; | ||
|
||
yield [ // test case-insensitive skip suffixes | ||
[], | ||
[new FileWithClass('foo.php', 'Bar', false, [])], | ||
[], | ||
[], | ||
['AR'], | ||
[] | ||
]; | ||
|
||
} | ||
} |
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.
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'd prefer to include this test as a single test fixture in the rule itselft, instead of adding a new unit test.
It would be easier to read for me later.
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.
the class is used at the top level
CheckCommand
which means I would need to test at the command level.. with all its dependencies?are you sure we want that ? :)
class-leak/src/Commands/CheckCommand.php
Lines 113 to 119 in 2fc838e
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 see. What I really want is the test to be simpler, as reading is quite complex now :)
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.
On other hand, we should not encourage using wrong class casing. This should be spotted and trigger the class name fix instead.
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.
phpstan itself does already error about class-name-case-mismatches. I think its not the job of class-leak to report it as a problem
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.
Exactly, this tool builds on top of PHPStan best quality code. Let PHPStan handle these 👍