-
-
Notifications
You must be signed in to change notification settings - Fork 82
Increase test coverage for --sniffs
and --exclude
options
#474
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
jrfnl
merged 27 commits into
PHPCSStandards:master
from
fredden:feature/tests/config.sniffs-exclude
May 14, 2024
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
6bba777
Increase test coverage for --sniffs and --exclude
fredden 46f27de
Merge remote-tracking branch 'upstream/master' into feature/tests/con…
fredden 2829da7
Fix tyop
fredden 61c7bf9
Use capital letters in comments
fredden c73d0b3
Quote fixed strings to avoid confustion with words
fredden 8e2603f
Add full-stops
fredden 3391c09
Rename variable
fredden f14581f
Sort 'use' statements
fredden 7ee42d1
Unwrap foreach; reduce test cases
fredden 13edab3
Name tests
fredden bd314c1
Test an empty string
fredden 1ffe83a
Rename testscase
fredden db76be8
Add another test case
fredden 389f112
Correct indentation
fredden bd249fb
Mark test as not-risky
fredden e92830d
Use more specific return type shape in comment
fredden b6df259
Assert configuration value is set on success
fredden b18272d
Add test case for setting multiple times
fredden 6400c61
Rename class again
fredden 35d8a65
Clarify shape of return array
fredden f7aa3ef
Clarify shape of return array
fredden fd5b8c7
Clarify shape of return array
fredden 801aefa
Correct comment
fredden 81bea03
Set 'position' argument
fredden 9d964ee
Avoid using internal method
fredden a0b31d9
Mark internal method as internal
fredden 70358b0
Revert "Mark internal method as internal"
fredden 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 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,140 @@ | ||
<?php | ||
/** | ||
* Tests for the \PHP_CodeSniffer\Config --sniffs and --exclude arguments. | ||
* | ||
* @author Dan Wallis <[email protected]> | ||
* @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence | ||
*/ | ||
|
||
namespace PHP_CodeSniffer\Tests\Core\Config; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use PHP_CodeSniffer\Tests\ConfigDouble; | ||
|
||
/** | ||
* Tests for the \PHP_CodeSniffer\Config --sniffs and --exclude arguments. | ||
* | ||
* @covers \PHP_CodeSniffer\Config::processLongArgument | ||
*/ | ||
final class SniffListTest extends TestCase | ||
fredden marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
|
||
|
||
/** | ||
* Ensure that the expected error message is returned for invalid arguments | ||
* | ||
* @param string $argument sniffs or exclude | ||
* @param string $value list of sniffs to include / exclude | ||
* @param string $message expected error message text | ||
fredden marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* | ||
* @return void | ||
* @dataProvider dataInvalidSniffs | ||
*/ | ||
public function testInvalid($argument, $value, $message) | ||
{ | ||
$config = new ConfigDouble(); | ||
$exception = 'PHP_CodeSniffer\Exceptions\DeepExitException'; | ||
|
||
if (method_exists($this, 'expectException') === true) { | ||
// PHPUnit 5+. | ||
$this->expectException($exception); | ||
$this->expectExceptionMessage($message); | ||
} else { | ||
// PHPUnit 4. | ||
$this->setExpectedException($exception, $message); | ||
} | ||
|
||
$config->processLongArgument($argument.'='.$value, 0); | ||
|
||
}//end testInvalid() | ||
|
||
|
||
/** | ||
* Date provider for testInvalid() | ||
fredden marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* | ||
* @see self::testInvalid() | ||
* @return array | ||
fredden marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
public static function dataInvalidSniffs() | ||
{ | ||
$arguments = [ | ||
'sniffs', | ||
'exclude', | ||
]; | ||
$result = []; | ||
fredden marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
$sniffs = []; | ||
|
||
$types = [ | ||
'Standard', | ||
'Standard.Category', | ||
'Standard.Category.Sniff.Code', | ||
]; | ||
foreach ($types as $value) { | ||
$sniffs[$value] = $value; | ||
$sniffs['Standard.Category.Sniff,B'.$value] = 'B'.$value; | ||
foreach ($types as $extra) { | ||
$sniffs['A'.$value.',B'.$extra] = 'A'.$value; | ||
} | ||
} | ||
|
||
$messageTemplate = 'ERROR: The specified sniff code "%s" is invalid'.PHP_EOL.PHP_EOL; | ||
foreach ($arguments as $argument) { | ||
foreach ($sniffs as $input => $output) { | ||
$result[] = [ | ||
fredden marked this conversation as resolved.
Show resolved
Hide resolved
|
||
'argument' => $argument, | ||
'value' => $input, | ||
'message' => sprintf($messageTemplate, $output), | ||
]; | ||
} | ||
} | ||
|
||
fredden marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return $result; | ||
fredden marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
}//end dataInvalidSniffs() | ||
|
||
|
||
/** | ||
* Ensure that the valid data does not throw an exception | ||
* | ||
* @param string $argument sniffs or exclude | ||
* @param string $value list of sniffs to include or exclude | ||
fredden marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* | ||
* @return void | ||
* @dataProvider dataValidSniffs | ||
*/ | ||
public function testValid($argument, $value) | ||
{ | ||
$config = new ConfigDouble(); | ||
$config->processLongArgument($argument.'='.$value, 0); | ||
|
||
fredden marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}//end testValid() | ||
|
||
|
||
/** | ||
* Data provider for testValid() | ||
fredden marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* | ||
* @see self::testValid() | ||
* @return array | ||
fredden marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
public static function dataValidSniffs() | ||
fredden marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
$arguments = [ | ||
'sniffs', | ||
'exclude', | ||
]; | ||
$result = []; | ||
|
||
foreach ($arguments as $argument) { | ||
$result[] = [ | ||
fredden marked this conversation as resolved.
Show resolved
Hide resolved
|
||
'argument' => $argument, | ||
'value' => 'Standard.Category.Sniff', | ||
]; | ||
} | ||
|
||
return $result; | ||
|
||
}//end dataValidSniffs() | ||
|
||
fredden marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
}//end class |
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.