Skip to content
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

Increase test coverage for --sniffs and --exclude options #474

Merged
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 Apr 28, 2024
46f27de
Merge remote-tracking branch 'upstream/master' into feature/tests/con…
fredden May 5, 2024
2829da7
Fix tyop
fredden May 5, 2024
61c7bf9
Use capital letters in comments
fredden May 5, 2024
c73d0b3
Quote fixed strings to avoid confustion with words
fredden May 5, 2024
8e2603f
Add full-stops
fredden May 5, 2024
3391c09
Rename variable
fredden May 5, 2024
f14581f
Sort 'use' statements
fredden May 5, 2024
7ee42d1
Unwrap foreach; reduce test cases
fredden May 5, 2024
13edab3
Name tests
fredden May 5, 2024
bd314c1
Test an empty string
fredden May 5, 2024
1ffe83a
Rename testscase
fredden May 5, 2024
db76be8
Add another test case
fredden May 6, 2024
389f112
Correct indentation
fredden May 6, 2024
bd249fb
Mark test as not-risky
fredden May 6, 2024
e92830d
Use more specific return type shape in comment
fredden May 6, 2024
b6df259
Assert configuration value is set on success
fredden May 6, 2024
b18272d
Add test case for setting multiple times
fredden May 6, 2024
6400c61
Rename class again
fredden May 8, 2024
35d8a65
Clarify shape of return array
fredden May 13, 2024
f7aa3ef
Clarify shape of return array
fredden May 13, 2024
fd5b8c7
Clarify shape of return array
fredden May 13, 2024
801aefa
Correct comment
fredden May 13, 2024
81bea03
Set 'position' argument
fredden May 13, 2024
9d964ee
Avoid using internal method
fredden May 14, 2024
a0b31d9
Mark internal method as internal
fredden May 14, 2024
70358b0
Revert "Mark internal method as internal"
fredden May 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
140 changes: 140 additions & 0 deletions tests/Core/Config/SniffListTest.php
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 <dan@wallis.nz>
* @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;
fredden marked this conversation as resolved.
Show resolved Hide resolved

/**
* 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