Skip to content

Commit b813cd6

Browse files
committed
Check paths are accepted if no exclude-pattern matches.
1 parent 8c94cf9 commit b813cd6

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

tests/Core/AllTests.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
require_once 'File/GetMethodParametersTest.php';
2222
require_once 'File/GetMethodPropertiesTest.php';
2323
require_once 'File/IsReferenceTest.php';
24+
require_once 'Filters/Filter/AcceptTest.php';
2425

2526
class AllTests
2627
{
@@ -55,6 +56,7 @@ public static function suite()
5556
$suite->addTestSuite('PHP_CodeSniffer\Tests\Core\File\GetMethodParametersTest');
5657
$suite->addTestSuite('PHP_CodeSniffer\Tests\Core\File\GetMethodPropertiesTest');
5758
$suite->addTestSuite('PHP_CodeSniffer\Tests\Core\File\IsReferenceTest');
59+
$suite->addTestSuite('PHP_CodeSniffer\Tests\Core\Filters\Filter\AcceptTest');
5860
return $suite;
5961

6062
}//end suite()
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0"?>
2+
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PHP_CodeSniffer" xsi:noNamespaceSchemaLocation="phpcs.xsd">
3+
<description>The coding standard for PHP_CodeSniffer itself.</description>
4+
5+
<rule ref="Generic">
6+
<exclude-pattern>/anything/</exclude-pattern>
7+
</rule>
8+
</ruleset>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
/**
3+
* Tests for the \PHP_CodeSniffer\Filters\Filter::accept method.
4+
*
5+
* @author Willington Vega <wvega@wvega.com>
6+
* @copyright 2006-2018 Squiz Pty Ltd (ABN 77 084 670 600)
7+
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
8+
*/
9+
10+
namespace PHP_CodeSniffer\Tests\Core\Filters\Filter;
11+
12+
use PHP_CodeSniffer\Config;
13+
use PHP_CodeSniffer\Filters\Filter;
14+
use PHP_CodeSniffer\Ruleset;
15+
use PHPUnit\Framework\TestCase;
16+
17+
class AcceptTest extends TestCase
18+
{
19+
20+
21+
/**
22+
* Test paths that include the name of a standard with associated
23+
* exclude-patterns are still accepted.
24+
*
25+
* @return void
26+
*/
27+
public function testExcludePatternsForStandards()
28+
{
29+
$standard = __DIR__.'/'.basename(__FILE__, '.php').'.inc';
30+
$config = new Config(["--standard=$standard"]);
31+
$ruleset = new Ruleset($config);
32+
33+
$paths = ['/path/to/generic-project/src/Main.php'];
34+
35+
$fakeDI = new \RecursiveArrayIterator($paths);
36+
$filter = new Filter($fakeDI, '/path/to/generic-project/src', $config, $ruleset);
37+
$iterator = new \RecursiveIteratorIterator($filter);
38+
$files = [];
39+
40+
foreach ($iterator as $file) {
41+
$files[] = $file;
42+
}
43+
44+
$this->assertEquals($paths, $files);
45+
46+
}//end testExcludePatternsForStandards()
47+
48+
49+
}//end class

0 commit comments

Comments
 (0)