From 38e6b528231d9f1552a7d7603df76fccc23fc22f Mon Sep 17 00:00:00 2001 From: Manuel Pichler Date: Sat, 8 Jan 2011 23:44:44 +0100 Subject: [PATCH] - Fixed #191: New implementation of --ignore only accepts relative paths. --- CHANGELOG | 8 +- PHP/Depend/Input/CompositeFilter.php | 9 +- PHP/Depend/Input/ExcludePathFilter.php | 56 +++++++++-- PHP/Depend/Input/ExtensionFilter.php | 9 +- PHP/Depend/Input/FilterI.php | 7 +- PHP/Depend/Input/Iterator.php | 26 +++-- tests/PHP/Depend/Bugs/AllTests.php | 2 + ...erShouldFilterByAbsolutePathBug191Test.php | 95 +++++++++++++++++++ ...rShouldOnlyFilterOnLocalPathBug164Test.php | 6 +- .../PHP/Depend/Input/CompositeFilterTest.php | 6 +- tests/PHP/Depend/Input/DummyFilter.php | 7 +- .../Depend/Input/ExcludePathFilterTest.php | 94 +++++++++++++++++- .../PHP/Depend/Input/ExtensionFilterTest.php | 2 +- tests/PHP/Depend/Input/IteratorTest.php | 18 ++-- .../DependExcludePathFilterTest.php | 59 +++++++++++- .../Integration/FilteredClass.php | 0 .../ProcessedClass.php | 0 .../Integration/FilteredClass.php | 8 ++ .../ProcessedClass.php | 8 ++ .../Integration/FilteredClass.php | 8 ++ .../ProcessedClass.php | 8 ++ 21 files changed, 380 insertions(+), 56 deletions(-) create mode 100644 tests/PHP/Depend/Bugs/ExcludePathFilterShouldFilterByAbsolutePathBug191Test.php rename tests/PHP/Depend/_code/Integration/DependExcludePathFilter/{testPhpDependOnlyFiltersLocalPath => testPDependFiltersByAbsolutePath}/Integration/FilteredClass.php (100%) rename tests/PHP/Depend/_code/Integration/DependExcludePathFilter/{testPhpDependOnlyFiltersLocalPath => testPDependFiltersByAbsolutePath}/ProcessedClass.php (100%) create mode 100644 tests/PHP/Depend/_code/Integration/DependExcludePathFilter/testPDependFiltersByRelativePath/Integration/FilteredClass.php create mode 100644 tests/PHP/Depend/_code/Integration/DependExcludePathFilter/testPDependFiltersByRelativePath/ProcessedClass.php create mode 100644 tests/PHP/Depend/_code/Integration/DependExcludePathFilter/testPDependNotFiltersByOverlappingPathMatch/Integration/FilteredClass.php create mode 100644 tests/PHP/Depend/_code/Integration/DependExcludePathFilter/testPDependNotFiltersByOverlappingPathMatch/ProcessedClass.php diff --git a/CHANGELOG b/CHANGELOG index 5977bc2d4..2e676f189 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,9 +1,3 @@ -PHP_Depend 0.11.0 ------------------ - -- Fixed #189: Invalid Start/End Line/Column for object method - invocation. Fixed in commit #c6cc9dd. - PHP_Depend 0.10.0 ----------------- @@ -41,6 +35,8 @@ PHP_Depend 0.10.0 (Unexpected token ASCII 39). Indirectly fixed in this release. - Fixed #182: Clone is a valid function, method and type name in older php versions. Fixed with git commit #b18bf37. +- Fixed #189: Invalid Start/End Line/Column for object method + invocation. Fixed in commit #c6cc9dd. PHP_depend 0.9.20 ----------------- diff --git a/PHP/Depend/Input/CompositeFilter.php b/PHP/Depend/Input/CompositeFilter.php index ea3fffac5..ba8f64166 100644 --- a/PHP/Depend/Input/CompositeFilter.php +++ b/PHP/Depend/Input/CompositeFilter.php @@ -84,17 +84,18 @@ public function append(PHP_Depend_Input_FilterI $filter) * Delegates the given $localPath object to all aggregated filters. * Returns true if this filter accepts the given path. * - * @param string $localPath The local/relative path to the specified root. + * @param string $relative The relative path to the specified root. + * @param string $absolute The absolute path to a source file. * * @return boolean */ - public function accept($localPath) + public function accept($relative, $absolute) { foreach ($this->filters as $filter) { - if (false === $filter->accept($localPath)) { + if (false === $filter->accept($relative, $absolute)) { return false; } } return true; } -} \ No newline at end of file +} diff --git a/PHP/Depend/Input/ExcludePathFilter.php b/PHP/Depend/Input/ExcludePathFilter.php index d01152333..5083f6d48 100644 --- a/PHP/Depend/Input/ExcludePathFilter.php +++ b/PHP/Depend/Input/ExcludePathFilter.php @@ -61,11 +61,20 @@ class PHP_Depend_Input_ExcludePathFilter implements PHP_Depend_Input_FilterI { /** - * Regular expression that should not match against the file path. + * Regular expression that should not match against the relative file paths. * - * @var string $regexp + * @var string + * @since 0.10.0 */ - protected $regexp = ''; + protected $relative = ''; + + /** + * Regular expression that should not match against the absolute file paths. + * + * @var string + * @since 0.10.0 + */ + protected $absolute = ''; /** * Constructs a new exclude path filter instance and accepts an array of @@ -75,21 +84,50 @@ class PHP_Depend_Input_ExcludePathFilter implements PHP_Depend_Input_FilterI */ public function __construct(array $patterns) { - $regexp = join('|', array_map('preg_quote', $patterns)); - $regexp = str_replace(array('\*'), array('.*'), $regexp); + $quoted = array_map('preg_quote', $patterns); - $this->regexp = "({$regexp})i"; + $this->relative = '(' . str_replace('\*', '.*', join('|', $quoted)) . ')i'; + $this->absolute = '(^' . str_replace('\*', '.*', join('|^', $quoted)) . ')i'; } /** * Returns true if this filter accepts the given path. * - * @param string $localPath The local/relative path to the specified root. + * @param string $relative The relative path to the specified root. + * @param string $absolute The absolute path to a source file. + * + * @return boolean + */ + public function accept($relative, $absolute) + { + return ($this->notRelative($relative) && $this->notAbsolute($absolute)); + } + + /** + * This method checks if the given $path does not match against the + * exclude patterns as an absolute path. + * + * @param string $path The absolute path to a source file. + * + * @return boolean + * @since 0.10.0 + */ + protected function notAbsolute($path) + { + return (preg_match($this->absolute, $path) === 0); + } + + /** + * This method checks if the given $path does not match against the + * exclude patterns as an relative path. + * + * @param string $path The relative path to a source file. * * @return boolean + * @since 0.10.0 */ - public function accept($localPath) + protected function notRelative($path) { - return (preg_match($this->regexp, $localPath) === 0); + return (preg_match($this->relative, $path) === 0); } } diff --git a/PHP/Depend/Input/ExtensionFilter.php b/PHP/Depend/Input/ExtensionFilter.php index 8a7243d97..c3301a0d9 100644 --- a/PHP/Depend/Input/ExtensionFilter.php +++ b/PHP/Depend/Input/ExtensionFilter.php @@ -79,15 +79,16 @@ public function __construct(array $extensions) } /** - * Returns true if this filter accepts the given path. + * Returns true if this filter accepts the given paths. * - * @param string $localPath The local/relative path to the specified root. + * @param string $relative The relative path to the specified root. + * @param string $absolute The absolute path to a source file. * * @return boolean */ - public function accept($localPath) + public function accept($relative, $absolute) { - $extension = pathinfo($localPath, PATHINFO_EXTENSION); + $extension = pathinfo($relative, PATHINFO_EXTENSION); return in_array($extension, $this->extensions); } diff --git a/PHP/Depend/Input/FilterI.php b/PHP/Depend/Input/FilterI.php index 59a954c88..8d307ef03 100644 --- a/PHP/Depend/Input/FilterI.php +++ b/PHP/Depend/Input/FilterI.php @@ -61,11 +61,12 @@ interface PHP_Depend_Input_FilterI { /** - * Returns true if this filter accepts the given path. + * Returns true if this filter accepts the given paths. * - * @param string $localPath The local/relative path to the specified root. + * @param string $relative The relative path to the specified root. + * @param string $absolute The absolute path to a source file. * * @return boolean */ - function accept($localPath); + function accept($relative, $absolute); } \ No newline at end of file diff --git a/PHP/Depend/Input/Iterator.php b/PHP/Depend/Input/Iterator.php index a7ea6c818..12ec1f37e 100644 --- a/PHP/Depend/Input/Iterator.php +++ b/PHP/Depend/Input/Iterator.php @@ -78,16 +78,16 @@ class PHP_Depend_Input_Iterator extends FilterIterator /** * Constructs a new file filter iterator. * - * @param Iterator $it The inner iterator. + * @param Iterator $iterator The inner iterator. * @param PHP_Depend_Input_FilterI $filter The filter object. * @param string $rootPath Optional root path for the files. */ public function __construct( - Iterator $it, + Iterator $iterator, PHP_Depend_Input_FilterI $filter, $rootPath = null ) { - parent::__construct($it); + parent::__construct($iterator); $this->filter = $filter; $this->rootPath = $rootPath; @@ -100,7 +100,18 @@ public function __construct( */ public function accept() { - return $this->filter->accept($this->getLocalPath()); + return $this->filter->accept($this->getLocalPath(), $this->getFullPath()); + } + + /** + * Returns the full qualified realpath for the currently active file. + * + * @return string + * @since 0.10.0 + */ + protected function getFullPath() + { + return $this->getInnerIterator()->current()->getRealpath(); } /** @@ -112,10 +123,9 @@ public function accept() */ protected function getLocalPath() { - $localPath = $this->getInnerIterator()->current(); - if ($this->rootPath && 0 === strpos($localPath, $this->rootPath)) { - $localPath = substr($localPath, strlen($this->rootPath)); + if ($this->rootPath && 0 === strpos($this->getFullPath(), $this->rootPath)) { + return substr($this->getFullPath(), strlen($this->rootPath)); } - return $localPath; + return $this->getFullPath(); } } \ No newline at end of file diff --git a/tests/PHP/Depend/Bugs/AllTests.php b/tests/PHP/Depend/Bugs/AllTests.php index 797705e8b..bd9fb9a4d 100644 --- a/tests/PHP/Depend/Bugs/AllTests.php +++ b/tests/PHP/Depend/Bugs/AllTests.php @@ -85,6 +85,7 @@ require_once dirname(__FILE__) . '/ClassInterfaceSizeShouldNotSumComplexityBug176Test.php'; require_once dirname(__FILE__) . '/UnexpectedTokenAsciiChar39Bug181Test.php'; require_once dirname(__FILE__) . '/CloneIsValidNameInOlderPhpVersionsBug182Test.php'; +require_once dirname(__FILE__) . '/ExcludePathFilterShouldFilterByAbsolutePathBug191Test.php'; /** * Test suite for bugs meta package. @@ -148,6 +149,7 @@ public static function suite() $suite->addTestSuite('PHP_Depend_Bugs_ClassInterfaceSizeShouldNotSumComplexityBug176Test'); $suite->addTestSuite('PHP_Depend_Bugs_UnexpectedTokenAsciiChar39Bug181Test'); $suite->addTestSuite('PHP_Depend_Bugs_CloneIsValidNameInOlderPhpVersionsBug182Test'); + $suite->addTestSuite('PHP_Depend_Input_ExcludePathFilterShouldFilterByAbsolutePathBug191Test'); return $suite; } diff --git a/tests/PHP/Depend/Bugs/ExcludePathFilterShouldFilterByAbsolutePathBug191Test.php b/tests/PHP/Depend/Bugs/ExcludePathFilterShouldFilterByAbsolutePathBug191Test.php new file mode 100644 index 000000000..003e62277 --- /dev/null +++ b/tests/PHP/Depend/Bugs/ExcludePathFilterShouldFilterByAbsolutePathBug191Test.php @@ -0,0 +1,95 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Manuel Pichler nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category PHP + * @package PHP_Depend + * @subpackage Bugs + * @author Manuel Pichler + * @copyright 2008-2010 Manuel Pichler. All rights reserved. + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pdepend.org/ + */ + +require_once dirname(__FILE__) . '/AbstractTest.php'; + +/** + * Test case for bug #191. + * + * @category PHP + * @package PHP_Depend + * @subpackage Bugs + * @author Manuel Pichler + * @copyright 2008-2010 Manuel Pichler. All rights reserved. + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://tracker.pdepend.org/pdepend/issue_tracker/issue/191 + * + * @covers stdClass + */ +class PHP_Depend_Input_ExcludePathFilterShouldFilterByAbsolutePathBug191Test + extends PHP_Depend_Bugs_AbstractTest +{ + /** + * testAbsoluteUnixPathAsFilterPattern + * + * @return void + * @group pdepend + * @group pdepend::bugs + * @group regressiontest + */ + public function testAbsoluteUnixPathAsFilterPattern() + { + $filter = new PHP_Depend_Input_ExcludePathFilter(array('/foo/bar')); + self::assertFalse($filter->accept('/baz', '/foo/bar/baz')); + } + + /** + * testAbsoluteWindowsPathAsFilterPattern + * + * @return void + * @group pdepend + * @group pdepend::bugs + * @group regressiontest + */ + public function testAbsoluteWindowsPathAsFilterPattern() + { + $filter = new PHP_Depend_Input_ExcludePathFilter(array('c:\workspace\bar')); + self::assertFalse($filter->accept('\baz', 'c:\workspace\bar\baz')); + } +} \ No newline at end of file diff --git a/tests/PHP/Depend/Bugs/InputIteratorShouldOnlyFilterOnLocalPathBug164Test.php b/tests/PHP/Depend/Bugs/InputIteratorShouldOnlyFilterOnLocalPathBug164Test.php index 6f1ad3111..fda903ecd 100644 --- a/tests/PHP/Depend/Bugs/InputIteratorShouldOnlyFilterOnLocalPathBug164Test.php +++ b/tests/PHP/Depend/Bugs/InputIteratorShouldOnlyFilterOnLocalPathBug164Test.php @@ -78,10 +78,12 @@ public function testIteratorOnlyPassesLocalPathToFilter() $filter = $this->getMock('PHP_Depend_Input_FilterI'); $filter->expects($this->once()) ->method('accept') - ->with(self::equalTo('/baz')); + ->with(self::equalTo(DIRECTORY_SEPARATOR . basename(__FILE__))); $iterator = new PHP_Depend_Input_Iterator( - new ArrayIterator(array('/foo/bar/baz')), $filter, '/foo/bar' + new ArrayIterator(array(new SplFileInfo(__FILE__))), + $filter, + dirname(__FILE__) ); $iterator->accept(); } diff --git a/tests/PHP/Depend/Input/CompositeFilterTest.php b/tests/PHP/Depend/Input/CompositeFilterTest.php index be445d913..ef52fe3aa 100644 --- a/tests/PHP/Depend/Input/CompositeFilterTest.php +++ b/tests/PHP/Depend/Input/CompositeFilterTest.php @@ -80,7 +80,7 @@ public function testCompositeInvokesFirstAcceptInFilterChain() $composite = new PHP_Depend_Input_CompositeFilter(); $composite->append($filter0); - $composite->accept(dirname(__FILE__)); + $composite->accept(dirname(__FILE__), dirname(__FILE__)); $this->assertTrue($filter0->invoked); } @@ -102,7 +102,7 @@ public function testCompositeInvokesNextAcceptIfPreviousAcceptReturnsTrue() $composite->append($filter0); $composite->append($filter1); - $composite->accept(dirname(__FILE__)); + $composite->accept(dirname(__FILE__), dirname(__FILE__)); $this->assertTrue($filter1->invoked); } @@ -124,7 +124,7 @@ public function testCompositeNotInvokesNextAcceptIfPreviousAcceptReturnsTrue() $composite->append($filter0); $composite->append($filter1); - $composite->accept(dirname(__FILE__)); + $composite->accept(dirname(__FILE__), dirname(__FILE__)); $this->assertFalse($filter1->invoked); } diff --git a/tests/PHP/Depend/Input/DummyFilter.php b/tests/PHP/Depend/Input/DummyFilter.php index 86fcdcf4d..03c33b99d 100644 --- a/tests/PHP/Depend/Input/DummyFilter.php +++ b/tests/PHP/Depend/Input/DummyFilter.php @@ -87,13 +87,14 @@ public function __construct($returnValue) } /** - * Returns true if this filter accepts the given path. + * Returns true if this filter accepts the given paths. * - * @param string $localPath The local/relative path to the specified root. + * @param string $relative The relative path to the specified root. + * @param string $absolute The absolute path to a source file. * * @return boolean */ - public function accept($localPath) + public function accept($relative, $absolute) { $this->invoked = true; diff --git a/tests/PHP/Depend/Input/ExcludePathFilterTest.php b/tests/PHP/Depend/Input/ExcludePathFilterTest.php index 5ad68450f..69beb80aa 100644 --- a/tests/PHP/Depend/Input/ExcludePathFilterTest.php +++ b/tests/PHP/Depend/Input/ExcludePathFilterTest.php @@ -64,6 +64,98 @@ */ class PHP_Depend_Input_ExcludePathFilterTest extends PHP_Depend_AbstractTest { + /** + * testAbsoluteUnixPathAsFilterPatternMatches + * + * @return void + * @group pdepend + * @group pdepend::input + * @group unittest + */ + public function testAbsoluteUnixPathAsFilterPatternMatches() + { + $filter = new PHP_Depend_Input_ExcludePathFilter(array('/foo/bar')); + self::assertFalse($filter->accept('/baz', '/foo/bar/baz')); + } + + /** + * testAbsoluteUnixPathAsFilterPatternNotMatches + * + * @return void + * @group pdepend + * @group pdepend::input + * @group unittest + */ + public function testAbsoluteUnixPathAsFilterPatternNotMatches() + { + $filter = new PHP_Depend_Input_ExcludePathFilter(array('/foo/bar')); + self::assertTrue($filter->accept('/foo/baz/bar', '/foo/baz/bar')); + } + + /** + * testUnixPathAsFilterPatternNotMatchesPartial + * + * @return void + * @group pdepend + * @group pdepend::input + * @group unittest + */ + public function testUnixPathAsFilterPatternNotMatchesPartial() + { + $pattern = 'PHP_Depend-git/PHP'; + $absolute = '/home/manuel/workspace/PHP_Depend-git/PHP/Depend.php'; + $relative = '/PHP/Depend.php'; + + $filter = new PHP_Depend_Input_ExcludePathFilter(array($pattern)); + self::assertTrue($filter->accept($relative, $absolute)); + } + + /** + * testAbsoluteWindowsPathAsFilterPatternMatches + * + * @return void + * @group pdepend + * @group pdepend::input + * @group unittest + */ + public function testAbsoluteWindowsPathAsFilterPatternMatches() + { + $filter = new PHP_Depend_Input_ExcludePathFilter(array('c:\workspace\bar')); + self::assertFalse($filter->accept('\baz', 'c:\workspace\bar\baz')); + } + + /** + * testAbsoluteWindowsPathAsFilterPatternNotMatches + * + * @return void + * @group pdepend + * @group pdepend::input + * @group unittest + */ + public function testAbsoluteWindowsPathAsFilterPatternNotMatches() + { + $filter = new PHP_Depend_Input_ExcludePathFilter(array('c:\workspace\\')); + self::assertTrue($filter->accept('c:\workspac\bar', 'c:\workspac\bar')); + } + + /** + * testWindowsPathAsFilterPatternNotMatchesPartial + * + * @return void + * @group pdepend + * @group pdepend::input + * @group unittest + */ + public function testWindowsPathAsFilterPatternNotMatchesPartial() + { + $pattern = 'PHP_Depend-git\PHP'; + $absolute = 'c:\workspace\PHP_Depend-git\PHP\Depend.php'; + $relative = '\PHP\Depend.php'; + + $filter = new PHP_Depend_Input_ExcludePathFilter(array($pattern)); + self::assertTrue($filter->accept($relative, $absolute)); + } + /** * testExcludePathFilterRejectsFile * @@ -164,7 +256,7 @@ protected function createFilteredFileList(array $excludes) $actual = array(); foreach ($files as $file) { - if ($filter->accept($file) + if ($filter->accept($file, $file) && $file->isFile() && false === stripos($file->getPathname(), '.svn') ) { diff --git a/tests/PHP/Depend/Input/ExtensionFilterTest.php b/tests/PHP/Depend/Input/ExtensionFilterTest.php index a63324227..37d1d8394 100644 --- a/tests/PHP/Depend/Input/ExtensionFilterTest.php +++ b/tests/PHP/Depend/Input/ExtensionFilterTest.php @@ -116,7 +116,7 @@ protected function createFilteredFileList(array $includes) $actual = array(); foreach ($files as $file) { - if ($filter->accept($file) + if ($filter->accept($file, $file) && $file->isFile() && false === stripos($file->getPathname(), '.svn') ) { diff --git a/tests/PHP/Depend/Input/IteratorTest.php b/tests/PHP/Depend/Input/IteratorTest.php index 8165359e6..d92ae548d 100644 --- a/tests/PHP/Depend/Input/IteratorTest.php +++ b/tests/PHP/Depend/Input/IteratorTest.php @@ -106,14 +106,16 @@ public function testIteratorWithMultipleFileExtensions() */ public function testIteratorPassesLocalPathToFilterWhenRootIsPresent() { - $files = new ArrayIterator(array('/foo/bar/baz')); - $filter = $this->getMock('PHP_Depend_Input_FilterI'); $filter->expects($this->once()) ->method('accept') - ->with(self::equalTo('/bar/baz')); + ->with(self::equalTo(DIRECTORY_SEPARATOR . basename(__FILE__))); - $iterator = new PHP_Depend_Input_Iterator($files, $filter, '/foo'); + $iterator = new PHP_Depend_Input_Iterator( + new ArrayIterator(array(new SplFileInfo(__FILE__))), + $filter, + dirname(__FILE__) + ); $iterator->accept(); } @@ -127,12 +129,12 @@ public function testIteratorPassesLocalPathToFilterWhenRootIsPresent() */ public function testIteratorPassesAbsolutePathToFilterWhenNoRootIsPresent() { - $files = new ArrayIterator(array('/foo/bar/baz')); + $files = new ArrayIterator(array(new SplFileInfo(__FILE__))); $filter = $this->getMock('PHP_Depend_Input_FilterI'); $filter->expects($this->once()) ->method('accept') - ->with(self::equalTo('/foo/bar/baz')); + ->with(self::equalTo(__FILE__), self::equalTo(__FILE__)); $iterator = new PHP_Depend_Input_Iterator($files, $filter); $iterator->accept(); @@ -148,12 +150,12 @@ public function testIteratorPassesAbsolutePathToFilterWhenNoRootIsPresent() */ public function testIteratorPassesAbsolutePathToFilterWhenRootNotMatches() { - $files = new ArrayIterator(array('/foo/bar/baz')); + $files = new ArrayIterator(array(new SplFileInfo(__FILE__))); $filter = $this->getMock('PHP_Depend_Input_FilterI'); $filter->expects($this->once()) ->method('accept') - ->with(self::equalTo('/foo/bar/baz')); + ->with(self::equalTo(__FILE__), self::equalTo(__FILE__)); $iterator = new PHP_Depend_Input_Iterator($files, $filter, 'c:\foo'); $iterator->accept(); diff --git a/tests/PHP/Depend/Integration/DependExcludePathFilterTest.php b/tests/PHP/Depend/Integration/DependExcludePathFilterTest.php index f7a45f26f..846195f22 100644 --- a/tests/PHP/Depend/Integration/DependExcludePathFilterTest.php +++ b/tests/PHP/Depend/Integration/DependExcludePathFilterTest.php @@ -67,23 +67,74 @@ class PHP_Depend_Integration_DependExcludePathFilterTest extends PHP_Depend_AbstractTest { /** - * testPhpDependOnlyFiltersLocalPath + * testPDependFiltersByRelativePath * * @return void * @group pdepend * @group pdepend::integration * @group integrationtest */ - public function testPhpDependOnlyFiltersLocalPath() + public function testPDependFiltersByRelativePath() { $this->changeWorkingDirectory(); + $directory = self::createCodeResourceUriForTest(); + $pattern = DIRECTORY_SEPARATOR . 'Integration'; + + $pdepend = $this->createPDependFixture(); + $pdepend->addDirectory($directory); + $pdepend->addFileFilter( + new PHP_Depend_Input_ExcludePathFilter(array($pattern)) + ); + + self::assertEquals(1, count($pdepend->analyze())); + } + + /** + * testPDependFiltersByAbsolutePath + * + * @return void + * @group pdepend + * @group pdepend::integration + * @group integrationtest + */ + public function testPDependFiltersByAbsolutePath() + { + $this->changeWorkingDirectory(); + + $directory = self::createCodeResourceUriForTest(); + $pattern = $directory . DIRECTORY_SEPARATOR . 'Integration'; + $pdepend = $this->createPDependFixture(); - $pdepend->addDirectory(self::createCodeResourceUriForTest()); + $pdepend->addDirectory($directory); $pdepend->addFileFilter( - new PHP_Depend_Input_ExcludePathFilter(array('Integration')) + new PHP_Depend_Input_ExcludePathFilter(array($pattern)) ); self::assertEquals(1, count($pdepend->analyze())); } + + /** + * testPDependNotFiltersByOverlappingPathMatch + * + * @return void + * @group pdepend + * @group pdepend::integration + * @group integrationtest + */ + public function testPDependNotFiltersByOverlappingPathMatch() + { + $this->changeWorkingDirectory(); + + $directory = self::createCodeResourceUriForTest(); + $pattern = __FUNCTION__ . DIRECTORY_SEPARATOR . 'Integration'; + + $pdepend = $this->createPDependFixture(); + $pdepend->addDirectory($directory); + $pdepend->addFileFilter( + new PHP_Depend_Input_ExcludePathFilter(array($pattern)) + ); + + self::assertEquals(2, count($pdepend->analyze())); + } } \ No newline at end of file diff --git a/tests/PHP/Depend/_code/Integration/DependExcludePathFilter/testPhpDependOnlyFiltersLocalPath/Integration/FilteredClass.php b/tests/PHP/Depend/_code/Integration/DependExcludePathFilter/testPDependFiltersByAbsolutePath/Integration/FilteredClass.php similarity index 100% rename from tests/PHP/Depend/_code/Integration/DependExcludePathFilter/testPhpDependOnlyFiltersLocalPath/Integration/FilteredClass.php rename to tests/PHP/Depend/_code/Integration/DependExcludePathFilter/testPDependFiltersByAbsolutePath/Integration/FilteredClass.php diff --git a/tests/PHP/Depend/_code/Integration/DependExcludePathFilter/testPhpDependOnlyFiltersLocalPath/ProcessedClass.php b/tests/PHP/Depend/_code/Integration/DependExcludePathFilter/testPDependFiltersByAbsolutePath/ProcessedClass.php similarity index 100% rename from tests/PHP/Depend/_code/Integration/DependExcludePathFilter/testPhpDependOnlyFiltersLocalPath/ProcessedClass.php rename to tests/PHP/Depend/_code/Integration/DependExcludePathFilter/testPDependFiltersByAbsolutePath/ProcessedClass.php diff --git a/tests/PHP/Depend/_code/Integration/DependExcludePathFilter/testPDependFiltersByRelativePath/Integration/FilteredClass.php b/tests/PHP/Depend/_code/Integration/DependExcludePathFilter/testPDependFiltersByRelativePath/Integration/FilteredClass.php new file mode 100644 index 000000000..49346b88c --- /dev/null +++ b/tests/PHP/Depend/_code/Integration/DependExcludePathFilter/testPDependFiltersByRelativePath/Integration/FilteredClass.php @@ -0,0 +1,8 @@ +