-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Increase test coverage for --sniffs and --exclude
- Loading branch information
Showing
1 changed file
with
140 additions
and
0 deletions.
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
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 | ||
{ | ||
|
||
|
||
/** | ||
* 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 | ||
* | ||
* @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() | ||
* | ||
* @see self::testInvalid() | ||
* @return array | ||
*/ | ||
public static function dataInvalidSniffs() | ||
{ | ||
$arguments = [ | ||
'sniffs', | ||
'exclude', | ||
]; | ||
$result = []; | ||
|
||
$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[] = [ | ||
'argument' => $argument, | ||
'value' => $input, | ||
'message' => sprintf($messageTemplate, $output), | ||
]; | ||
} | ||
} | ||
|
||
return $result; | ||
|
||
}//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 | ||
* | ||
* @return void | ||
* @dataProvider dataValidSniffs | ||
*/ | ||
public function testValid($argument, $value) | ||
{ | ||
$config = new ConfigDouble(); | ||
$config->processLongArgument($argument.'='.$value, 0); | ||
|
||
}//end testValid() | ||
|
||
|
||
/** | ||
* Data provider for testValid() | ||
* | ||
* @see self::testValid() | ||
* @return array | ||
*/ | ||
public static function dataValidSniffs() | ||
{ | ||
$arguments = [ | ||
'sniffs', | ||
'exclude', | ||
]; | ||
$result = []; | ||
|
||
foreach ($arguments as $argument) { | ||
$result[] = [ | ||
'argument' => $argument, | ||
'value' => 'Standard.Category.Sniff', | ||
]; | ||
} | ||
|
||
return $result; | ||
|
||
}//end dataValidSniffs() | ||
|
||
|
||
}//end class |