Skip to content

Commit

Permalink
Check paths are accepted if no exclude-pattern matches.
Browse files Browse the repository at this point in the history
  • Loading branch information
wvega committed Jan 28, 2019
1 parent 8c94cf9 commit b813cd6
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/Core/AllTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
require_once 'File/GetMethodParametersTest.php';
require_once 'File/GetMethodPropertiesTest.php';
require_once 'File/IsReferenceTest.php';
require_once 'Filters/Filter/AcceptTest.php';

class AllTests
{
Expand Down Expand Up @@ -55,6 +56,7 @@ public static function suite()
$suite->addTestSuite('PHP_CodeSniffer\Tests\Core\File\GetMethodParametersTest');
$suite->addTestSuite('PHP_CodeSniffer\Tests\Core\File\GetMethodPropertiesTest');
$suite->addTestSuite('PHP_CodeSniffer\Tests\Core\File\IsReferenceTest');
$suite->addTestSuite('PHP_CodeSniffer\Tests\Core\Filters\Filter\AcceptTest');
return $suite;

}//end suite()
Expand Down
8 changes: 8 additions & 0 deletions tests/Core/Filters/Filter/AcceptTest.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PHP_CodeSniffer" xsi:noNamespaceSchemaLocation="phpcs.xsd">
<description>The coding standard for PHP_CodeSniffer itself.</description>

<rule ref="Generic">
<exclude-pattern>/anything/</exclude-pattern>
</rule>
</ruleset>
49 changes: 49 additions & 0 deletions tests/Core/Filters/Filter/AcceptTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* Tests for the \PHP_CodeSniffer\Filters\Filter::accept method.
*
* @author Willington Vega <wvega@wvega.com>
* @copyright 2006-2018 Squiz Pty Ltd (ABN 77 084 670 600)
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
*/

namespace PHP_CodeSniffer\Tests\Core\Filters\Filter;

use PHP_CodeSniffer\Config;
use PHP_CodeSniffer\Filters\Filter;
use PHP_CodeSniffer\Ruleset;
use PHPUnit\Framework\TestCase;

class AcceptTest extends TestCase
{


/**
* Test paths that include the name of a standard with associated
* exclude-patterns are still accepted.
*
* @return void
*/
public function testExcludePatternsForStandards()
{
$standard = __DIR__.'/'.basename(__FILE__, '.php').'.inc';
$config = new Config(["--standard=$standard"]);
$ruleset = new Ruleset($config);

$paths = ['/path/to/generic-project/src/Main.php'];

$fakeDI = new \RecursiveArrayIterator($paths);
$filter = new Filter($fakeDI, '/path/to/generic-project/src', $config, $ruleset);
$iterator = new \RecursiveIteratorIterator($filter);
$files = [];

foreach ($iterator as $file) {
$files[] = $file;
}

$this->assertEquals($paths, $files);

}//end testExcludePatternsForStandards()


}//end class

0 comments on commit b813cd6

Please sign in to comment.