Skip to content

Commit 89f3673

Browse files
committed
Increase test coverage for --sniffs and --exclude
1 parent 6119828 commit 89f3673

File tree

1 file changed

+132
-0
lines changed

1 file changed

+132
-0
lines changed

tests/Core/Config/SniffListTest.php

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
<?php
2+
/**
3+
* Tests for the \PHP_CodeSniffer\Config --sniffs and --exclude arguments.
4+
*
5+
* @author Dan Wallis <[email protected]>
6+
* @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
7+
*/
8+
9+
namespace PHP_CodeSniffer\Tests\Core\Config;
10+
11+
use PHPUnit\Framework\TestCase;
12+
use PHP_CodeSniffer\Tests\ConfigDouble;
13+
14+
/**
15+
* Tests for the \PHP_CodeSniffer\Config --sniffs and --exclude arguments.
16+
*
17+
* @covers \PHP_CodeSniffer\Config::processLongArgument
18+
*/
19+
final class SniffListTest extends TestCase
20+
{
21+
22+
23+
/**
24+
* Ensure that the expected error message is returned for invalid arguments
25+
*
26+
* @param string $argument sniffs or exclude
27+
* @param string $value list of sniffs to include / exclude
28+
* @param string $message expected error message text
29+
*
30+
* @return void
31+
* @dataProvider dataInvalidSniffs
32+
*/
33+
public function testInvalid($argument, $value, $message)
34+
{
35+
$config = new ConfigDouble();
36+
37+
$this->expectException('PHP_CodeSniffer\Exceptions\DeepExitException');
38+
$this->expectExceptionMessage($message);
39+
$config->processLongArgument($argument.'='.$value, 0);
40+
41+
}//end testInvalid()
42+
43+
44+
/**
45+
* Date provider for testInvalid()
46+
*
47+
* @see self::testInvalid()
48+
* @return array
49+
*/
50+
public static function dataInvalidSniffs()
51+
{
52+
$arguments = [
53+
'sniffs',
54+
'exclude',
55+
];
56+
$result = [];
57+
58+
$sniffs = [];
59+
60+
$types = [
61+
'Standard',
62+
'Standard.Category',
63+
'Standard.Category.Sniff.Code',
64+
];
65+
foreach ($types as $value) {
66+
$sniffs[$value] = $value;
67+
$sniffs['Standard.Category.Sniff,B'.$value] = 'B'.$value;
68+
foreach ($types as $extra) {
69+
$sniffs['A'.$value.',B'.$extra] = 'A'.$value;
70+
}
71+
}
72+
73+
$messageTemplate = 'ERROR: The specified sniff code "%s" is invalid'.PHP_EOL.PHP_EOL;
74+
foreach ($arguments as $argument) {
75+
foreach ($sniffs as $input => $output) {
76+
$result[] = [
77+
'argument' => $argument,
78+
'value' => $input,
79+
'message' => sprintf($messageTemplate, $output),
80+
];
81+
}
82+
}
83+
84+
return $result;
85+
86+
}//end dataInvalidSniffs()
87+
88+
89+
/**
90+
* Ensure that the valid data does not throw an exception
91+
*
92+
* @param string $argument sniffs or exclude
93+
* @param string $value list of sniffs to include or exclude
94+
*
95+
* @return void
96+
* @dataProvider dataValidSniffs
97+
*/
98+
public function testValid($argument, $value)
99+
{
100+
$config = new ConfigDouble();
101+
$config->processLongArgument($argument.'='.$value, 0);
102+
103+
}//end testValid()
104+
105+
106+
/**
107+
* Data provider for testValid()
108+
*
109+
* @see self::testValid()
110+
* @return array
111+
*/
112+
public static function dataValidSniffs()
113+
{
114+
$arguments = [
115+
'sniffs',
116+
'exclude',
117+
];
118+
$result = [];
119+
120+
foreach ($arguments as $argument) {
121+
$result[] = [
122+
'argument' => $argument,
123+
'value' => 'Standard.Category.Sniff',
124+
];
125+
}
126+
127+
return $result;
128+
129+
}//end dataValidSniffs()
130+
131+
132+
}//end class

0 commit comments

Comments
 (0)