From c08cf4b7f667847e30c4c7cd1aecec58cf595e89 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 15 Sep 2015 10:24:28 +0200 Subject: [PATCH] [Finder] Deprecate adapters and related classes --- .../Finder/Adapter/AbstractAdapter.php | 4 + .../Finder/Adapter/AbstractFindAdapter.php | 4 + .../Finder/Adapter/AdapterInterface.php | 2 + .../Finder/Adapter/BsdFindAdapter.php | 4 + .../Finder/Adapter/GnuFindAdapter.php | 4 + .../Component/Finder/Adapter/PhpAdapter.php | 4 + src/Symfony/Component/Finder/CHANGELOG.md | 5 + .../Exception/AdapterFailureException.php | 4 + .../OperationNotPermitedException.php | 4 + .../ShellCommandFailureException.php | 4 + src/Symfony/Component/Finder/Finder.php | 143 +++++++++++++++--- .../Finder/Iterator/FilePathsIterator.php | 4 + .../Component/Finder/Shell/Command.php | 4 + src/Symfony/Component/Finder/Shell/Shell.php | 4 + .../Component/Finder/Tests/BsdFinderTest.php | 10 +- .../Component/Finder/Tests/FinderTest.php | 24 +-- .../Component/Finder/Tests/GnuFinderTest.php | 10 +- .../Tests/Iterator/FilePathsIteratorTest.php | 3 + .../Component/Finder/Tests/PhpFinderTest.php | 45 ++++++ .../Finder/Tests/Shell/CommandTest.php | 3 + 20 files changed, 255 insertions(+), 34 deletions(-) create mode 100644 src/Symfony/Component/Finder/Tests/PhpFinderTest.php diff --git a/src/Symfony/Component/Finder/Adapter/AbstractAdapter.php b/src/Symfony/Component/Finder/Adapter/AbstractAdapter.php index 4ddd913174f9d..48f993da55d56 100644 --- a/src/Symfony/Component/Finder/Adapter/AbstractAdapter.php +++ b/src/Symfony/Component/Finder/Adapter/AbstractAdapter.php @@ -11,10 +11,14 @@ namespace Symfony\Component\Finder\Adapter; +@trigger_error('The '.__NAMESPACE__.'\AbstractAdapter class is deprecated since version 2.8 and will be removed in 3.0. Use directly the Finder class instead.', E_USER_DEPRECATED); + /** * Interface for finder engine implementations. * * @author Jean-François Simon + * + * @deprecated since 2.8, to be removed in 3.0. Use Finder instead. */ abstract class AbstractAdapter implements AdapterInterface { diff --git a/src/Symfony/Component/Finder/Adapter/AbstractFindAdapter.php b/src/Symfony/Component/Finder/Adapter/AbstractFindAdapter.php index 244301a739e29..a7fe248a027b2 100644 --- a/src/Symfony/Component/Finder/Adapter/AbstractFindAdapter.php +++ b/src/Symfony/Component/Finder/Adapter/AbstractFindAdapter.php @@ -11,6 +11,8 @@ namespace Symfony\Component\Finder\Adapter; +@trigger_error('The '.__NAMESPACE__.'\AbstractFindAdapter class is deprecated since version 2.8 and will be removed in 3.0. Use directly the Finder class instead.', E_USER_DEPRECATED); + use Symfony\Component\Finder\Exception\AccessDeniedException; use Symfony\Component\Finder\Iterator; use Symfony\Component\Finder\Shell\Shell; @@ -23,6 +25,8 @@ * Shell engine implementation using GNU find command. * * @author Jean-François Simon + * + * @deprecated since 2.8, to be removed in 3.0. Use Finder instead. */ abstract class AbstractFindAdapter extends AbstractAdapter { diff --git a/src/Symfony/Component/Finder/Adapter/AdapterInterface.php b/src/Symfony/Component/Finder/Adapter/AdapterInterface.php index bdc3a938701c9..27ead05988e0c 100644 --- a/src/Symfony/Component/Finder/Adapter/AdapterInterface.php +++ b/src/Symfony/Component/Finder/Adapter/AdapterInterface.php @@ -13,6 +13,8 @@ /** * @author Jean-François Simon + * + * @deprecated since 2.8, to be removed in 3.0. */ interface AdapterInterface { diff --git a/src/Symfony/Component/Finder/Adapter/BsdFindAdapter.php b/src/Symfony/Component/Finder/Adapter/BsdFindAdapter.php index 4a25baeb6fd18..caaad19a1e32a 100644 --- a/src/Symfony/Component/Finder/Adapter/BsdFindAdapter.php +++ b/src/Symfony/Component/Finder/Adapter/BsdFindAdapter.php @@ -11,6 +11,8 @@ namespace Symfony\Component\Finder\Adapter; +@trigger_error('The '.__NAMESPACE__.'\BsdFindAdapter class is deprecated since version 2.8 and will be removed in 3.0. Use directly the Finder class instead.', E_USER_DEPRECATED); + use Symfony\Component\Finder\Shell\Shell; use Symfony\Component\Finder\Shell\Command; use Symfony\Component\Finder\Iterator\SortableIterator; @@ -20,6 +22,8 @@ * Shell engine implementation using BSD find command. * * @author Jean-François Simon + * + * @deprecated since 2.8, to be removed in 3.0. Use Finder instead. */ class BsdFindAdapter extends AbstractFindAdapter { diff --git a/src/Symfony/Component/Finder/Adapter/GnuFindAdapter.php b/src/Symfony/Component/Finder/Adapter/GnuFindAdapter.php index 0fbf48ffa40f4..3888645ad6127 100644 --- a/src/Symfony/Component/Finder/Adapter/GnuFindAdapter.php +++ b/src/Symfony/Component/Finder/Adapter/GnuFindAdapter.php @@ -11,6 +11,8 @@ namespace Symfony\Component\Finder\Adapter; +@trigger_error('The '.__NAMESPACE__.'\GnuFindAdapter class is deprecated since version 2.8 and will be removed in 3.0. Use directly the Finder class instead.', E_USER_DEPRECATED); + use Symfony\Component\Finder\Shell\Shell; use Symfony\Component\Finder\Shell\Command; use Symfony\Component\Finder\Iterator\SortableIterator; @@ -20,6 +22,8 @@ * Shell engine implementation using GNU find command. * * @author Jean-François Simon + * + * @deprecated since 2.8, to be removed in 3.0. Use Finder instead. */ class GnuFindAdapter extends AbstractFindAdapter { diff --git a/src/Symfony/Component/Finder/Adapter/PhpAdapter.php b/src/Symfony/Component/Finder/Adapter/PhpAdapter.php index e8ada3671cfe6..3f2a070e495aa 100644 --- a/src/Symfony/Component/Finder/Adapter/PhpAdapter.php +++ b/src/Symfony/Component/Finder/Adapter/PhpAdapter.php @@ -11,12 +11,16 @@ namespace Symfony\Component\Finder\Adapter; +@trigger_error('The '.__NAMESPACE__.'\PhpAdapter class is deprecated since version 2.8 and will be removed in 3.0. Use directly the Finder class instead.', E_USER_DEPRECATED); + use Symfony\Component\Finder\Iterator; /** * PHP finder engine implementation. * * @author Jean-François Simon + * + * @deprecated since 2.8, to be removed in 3.0. Use Finder instead. */ class PhpAdapter extends AbstractAdapter { diff --git a/src/Symfony/Component/Finder/CHANGELOG.md b/src/Symfony/Component/Finder/CHANGELOG.md index f1dd7d526b288..a45c20825f5fc 100644 --- a/src/Symfony/Component/Finder/CHANGELOG.md +++ b/src/Symfony/Component/Finder/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +2.8.0 +----- + + * deprecated adapters and related classes + 2.5.0 ----- * added support for GLOB_BRACE in the paths passed to Finder::in() diff --git a/src/Symfony/Component/Finder/Exception/AdapterFailureException.php b/src/Symfony/Component/Finder/Exception/AdapterFailureException.php index 15fa22147d837..7229451b8c15d 100644 --- a/src/Symfony/Component/Finder/Exception/AdapterFailureException.php +++ b/src/Symfony/Component/Finder/Exception/AdapterFailureException.php @@ -11,12 +11,16 @@ namespace Symfony\Component\Finder\Exception; +@trigger_error('The '.__NAMESPACE__.'\AdapterFailureException class is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED); + use Symfony\Component\Finder\Adapter\AdapterInterface; /** * Base exception for all adapter failures. * * @author Jean-François Simon + * + * @deprecated since 2.8, to be removed in 3.0. */ class AdapterFailureException extends \RuntimeException implements ExceptionInterface { diff --git a/src/Symfony/Component/Finder/Exception/OperationNotPermitedException.php b/src/Symfony/Component/Finder/Exception/OperationNotPermitedException.php index 3663112259c4d..d75d6520d716a 100644 --- a/src/Symfony/Component/Finder/Exception/OperationNotPermitedException.php +++ b/src/Symfony/Component/Finder/Exception/OperationNotPermitedException.php @@ -11,8 +11,12 @@ namespace Symfony\Component\Finder\Exception; +@trigger_error('The '.__NAMESPACE__.'\OperationNotPermitedException class is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED); + /** * @author Jean-François Simon + * + * @deprecated since 2.8, to be removed in 3.0. */ class OperationNotPermitedException extends AdapterFailureException { diff --git a/src/Symfony/Component/Finder/Exception/ShellCommandFailureException.php b/src/Symfony/Component/Finder/Exception/ShellCommandFailureException.php index 2658f6a508fb5..10251bff96dba 100644 --- a/src/Symfony/Component/Finder/Exception/ShellCommandFailureException.php +++ b/src/Symfony/Component/Finder/Exception/ShellCommandFailureException.php @@ -11,11 +11,15 @@ namespace Symfony\Component\Finder\Exception; +@trigger_error('The '.__NAMESPACE__.'\ShellCommandFailureException class is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED); + use Symfony\Component\Finder\Adapter\AdapterInterface; use Symfony\Component\Finder\Shell\Command; /** * @author Jean-François Simon + * + * @deprecated since 2.8, to be removed in 3.0. */ class ShellCommandFailureException extends AdapterFailureException { diff --git a/src/Symfony/Component/Finder/Finder.php b/src/Symfony/Component/Finder/Finder.php index 70ef47c8214e6..29fb7bb9de125 100644 --- a/src/Symfony/Component/Finder/Finder.php +++ b/src/Symfony/Component/Finder/Finder.php @@ -62,7 +62,7 @@ class Finder implements \IteratorAggregate, \Countable private $iterators = array(); private $contains = array(); private $notContains = array(); - private $adapters = array(); + private $adapters = null; private $paths = array(); private $notPaths = array(); private $ignoreUnreadableDirs = false; @@ -75,13 +75,6 @@ class Finder implements \IteratorAggregate, \Countable public function __construct() { $this->ignore = static::IGNORE_VCS_FILES | static::IGNORE_DOT_FILES; - - $this - ->addAdapter(new GnuFindAdapter()) - ->addAdapter(new BsdFindAdapter()) - ->addAdapter(new PhpAdapter(), -50) - ->setAdapter('php') - ; } /** @@ -103,9 +96,15 @@ public static function create() * @param int $priority Highest is selected first * * @return Finder The current Finder instance + * + * @deprecated since 2.8, to be removed in 3.0. */ public function addAdapter(AdapterInterface $adapter, $priority = 0) { + @trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED); + + $this->initDefaultAdapters(); + $this->adapters[$adapter->getName()] = array( 'adapter' => $adapter, 'priority' => $priority, @@ -119,9 +118,15 @@ public function addAdapter(AdapterInterface $adapter, $priority = 0) * Sets the selected adapter to the best one according to the current platform the code is run on. * * @return Finder The current Finder instance + * + * @deprecated since 2.8, to be removed in 3.0. */ public function useBestAdapter() { + @trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED); + + $this->initDefaultAdapters(); + $this->resetAdapterSelection(); return $this->sortAdapters(); @@ -135,9 +140,15 @@ public function useBestAdapter() * @throws \InvalidArgumentException * * @return Finder The current Finder instance + * + * @deprecated since 2.8, to be removed in 3.0. */ public function setAdapter($name) { + @trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED); + + $this->initDefaultAdapters(); + if (!isset($this->adapters[$name])) { throw new \InvalidArgumentException(sprintf('Adapter "%s" does not exist.', $name)); } @@ -152,9 +163,13 @@ public function setAdapter($name) * Removes all adapters registered in the finder. * * @return Finder The current Finder instance + * + * @deprecated since 2.8, to be removed in 3.0. */ public function removeAdapters() { + @trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED); + $this->adapters = array(); return $this; @@ -164,9 +179,15 @@ public function removeAdapters() * Returns registered adapters ordered by priority without extra information. * * @return AdapterInterface[] + * + * @deprecated since 2.8, to be removed in 3.0. */ public function getAdapters() { + @trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED); + + $this->initDefaultAdapters(); + return array_values(array_map(function (array $adapter) { return $adapter['adapter']; }, $this->adapters)); @@ -774,8 +795,6 @@ private function sortAdapters() * @param $dir * * @return \Iterator - * - * @throws \RuntimeException When none of the adapters are supported */ private function searchInDirectory($dir) { @@ -787,18 +806,93 @@ private function searchInDirectory($dir) $this->notPaths[] = '#(^|/)\..+(/|$)#'; } - foreach ($this->adapters as $adapter) { - if ($adapter['adapter']->isSupported()) { - try { - return $this - ->buildAdapter($adapter['adapter']) - ->searchInDirectory($dir); - } catch (ExceptionInterface $e) { + if ($this->adapters) { + foreach ($this->adapters as $adapter) { + if ($adapter['adapter']->isSupported()) { + try { + return $this + ->buildAdapter($adapter['adapter']) + ->searchInDirectory($dir); + } catch (ExceptionInterface $e) { + } } } } - throw new \RuntimeException('No supported adapter found.'); + $minDepth = 0; + $maxDepth = PHP_INT_MAX; + + foreach ($this->depths as $comparator) { + switch ($comparator->getOperator()) { + case '>': + $minDepth = $comparator->getTarget() + 1; + break; + case '>=': + $minDepth = $comparator->getTarget(); + break; + case '<': + $maxDepth = $comparator->getTarget() - 1; + break; + case '<=': + $maxDepth = $comparator->getTarget(); + break; + default: + $minDepth = $maxDepth = $comparator->getTarget(); + } + } + + $flags = \RecursiveDirectoryIterator::SKIP_DOTS; + + if ($this->followLinks) { + $flags |= \RecursiveDirectoryIterator::FOLLOW_SYMLINKS; + } + + $iterator = new Iterator\RecursiveDirectoryIterator($dir, $flags, $this->ignoreUnreadableDirs); + + if ($this->exclude) { + $iterator = new Iterator\ExcludeDirectoryFilterIterator($iterator, $this->exclude); + } + + $iterator = new \RecursiveIteratorIterator($iterator, \RecursiveIteratorIterator::SELF_FIRST); + + if ($minDepth > 0 || $maxDepth < PHP_INT_MAX) { + $iterator = new Iterator\DepthRangeFilterIterator($iterator, $minDepth, $maxDepth); + } + + if ($this->mode) { + $iterator = new Iterator\FileTypeFilterIterator($iterator, $this->mode); + } + + if ($this->names || $this->notNames) { + $iterator = new Iterator\FilenameFilterIterator($iterator, $this->names, $this->notNames); + } + + if ($this->contains || $this->notContains) { + $iterator = new Iterator\FilecontentFilterIterator($iterator, $this->contains, $this->notContains); + } + + if ($this->sizes) { + $iterator = new Iterator\SizeRangeFilterIterator($iterator, $this->sizes); + } + + if ($this->dates) { + $iterator = new Iterator\DateRangeFilterIterator($iterator, $this->dates); + } + + if ($this->filters) { + $iterator = new Iterator\CustomFilterIterator($iterator, $this->filters); + } + + if ($this->paths || $this->notPaths) { + $iterator = new Iterator\PathFilterIterator($iterator, $this->paths, $this->notPaths); + } + + if ($this->sort) { + $iteratorAggregate = new Iterator\SortableIterator($iterator, $this->sort); + $iterator = $iteratorAggregate->getIterator(); + } + + return $iterator; } /** @@ -837,4 +931,17 @@ private function resetAdapterSelection() return $properties; }, $this->adapters); } + + private function initDefaultAdapters() + { + if (null === $this->adapters) { + $this->adapters = array(); + $this + ->addAdapter(new GnuFindAdapter()) + ->addAdapter(new BsdFindAdapter()) + ->addAdapter(new PhpAdapter(), -50) + ->setAdapter('php') + ; + } + } } diff --git a/src/Symfony/Component/Finder/Iterator/FilePathsIterator.php b/src/Symfony/Component/Finder/Iterator/FilePathsIterator.php index 4da2f5be012e6..74ada6b2d7160 100644 --- a/src/Symfony/Component/Finder/Iterator/FilePathsIterator.php +++ b/src/Symfony/Component/Finder/Iterator/FilePathsIterator.php @@ -11,12 +11,16 @@ namespace Symfony\Component\Finder\Iterator; +@trigger_error('The '.__NAMESPACE__.'\FilePathsIterator class is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED); + use Symfony\Component\Finder\SplFileInfo; /** * Iterate over shell command result. * * @author Jean-François Simon + * + * @deprecated since 2.8, to be removed in 3.0. */ class FilePathsIterator extends \ArrayIterator { diff --git a/src/Symfony/Component/Finder/Shell/Command.php b/src/Symfony/Component/Finder/Shell/Command.php index f8bd6a08514e9..c61fc6c712697 100644 --- a/src/Symfony/Component/Finder/Shell/Command.php +++ b/src/Symfony/Component/Finder/Shell/Command.php @@ -11,8 +11,12 @@ namespace Symfony\Component\Finder\Shell; +@trigger_error('The '.__NAMESPACE__.'\Command class is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED); + /** * @author Jean-François Simon + * + * @deprecated since 2.8, to be removed in 3.0. */ class Command { diff --git a/src/Symfony/Component/Finder/Shell/Shell.php b/src/Symfony/Component/Finder/Shell/Shell.php index 6d7bff33b4b02..0cd1e1f5582c0 100644 --- a/src/Symfony/Component/Finder/Shell/Shell.php +++ b/src/Symfony/Component/Finder/Shell/Shell.php @@ -11,8 +11,12 @@ namespace Symfony\Component\Finder\Shell; +@trigger_error('The '.__NAMESPACE__.'\Shell class is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED); + /** * @author Jean-François Simon + * + * @deprecated since 2.8, to be removed in 3.0. */ class Shell { diff --git a/src/Symfony/Component/Finder/Tests/BsdFinderTest.php b/src/Symfony/Component/Finder/Tests/BsdFinderTest.php index 42691a4318531..a7d800616625f 100644 --- a/src/Symfony/Component/Finder/Tests/BsdFinderTest.php +++ b/src/Symfony/Component/Finder/Tests/BsdFinderTest.php @@ -12,10 +12,14 @@ namespace Symfony\Component\Finder\Tests; use Symfony\Component\Finder\Adapter\BsdFindAdapter; +use Symfony\Component\Finder\Finder; +/** + * @group legacy + */ class BsdFinderTest extends FinderTest { - protected function getAdapter() + protected function buildFinder() { $adapter = new BsdFindAdapter(); @@ -23,6 +27,8 @@ protected function getAdapter() $this->markTestSkipped(get_class($adapter).' is not supported.'); } - return $adapter; + return Finder::create() + ->removeAdapters() + ->addAdapter($adapter); } } diff --git a/src/Symfony/Component/Finder/Tests/FinderTest.php b/src/Symfony/Component/Finder/Tests/FinderTest.php index 0f1fbd625d7e0..fb059895c1152 100644 --- a/src/Symfony/Component/Finder/Tests/FinderTest.php +++ b/src/Symfony/Component/Finder/Tests/FinderTest.php @@ -248,6 +248,7 @@ public function testIn() __DIR__.DIRECTORY_SEPARATOR.'BsdFinderTest.php', __DIR__.DIRECTORY_SEPARATOR.'FinderTest.php', __DIR__.DIRECTORY_SEPARATOR.'GnuFinderTest.php', + __DIR__.DIRECTORY_SEPARATOR.'PhpFinderTest.php', __DIR__.DIRECTORY_SEPARATOR.'GlobTest.php', ); @@ -531,6 +532,9 @@ public function testRegexSpecialCharsLocationWithPathRestrictionContainingStartF $this->assertIterator($this->toAbsoluteFixtures($expected), $finder); } + /** + * @group legacy + */ public function testAdaptersOrdering() { $finder = Finder::create() @@ -549,6 +553,9 @@ public function testAdaptersOrdering() ); } + /** + * @group legacy + */ public function testAdaptersChaining() { $iterator = new \ArrayIterator(array()); @@ -603,6 +610,9 @@ public function testPath($matchPatterns, $noMatchPatterns, array $expected) $this->assertIterator($this->toAbsoluteFixtures($expected), $finder); } + /** + * @group legacy + */ public function testAdapterSelection() { // test that by default, PhpAdapter is selected @@ -725,18 +735,8 @@ public function testIgnoredAccessDeniedException() } } - /** - * @return AdapterInterface - */ - protected function getAdapter() - { - return new PhpAdapter(); - } - - private function buildFinder() + protected function buildFinder() { - return Finder::create() - ->removeAdapters() - ->addAdapter($this->getAdapter()); + return Finder::create(); } } diff --git a/src/Symfony/Component/Finder/Tests/GnuFinderTest.php b/src/Symfony/Component/Finder/Tests/GnuFinderTest.php index 5c66723c1bea1..81b14d3021a53 100644 --- a/src/Symfony/Component/Finder/Tests/GnuFinderTest.php +++ b/src/Symfony/Component/Finder/Tests/GnuFinderTest.php @@ -12,10 +12,14 @@ namespace Symfony\Component\Finder\Tests; use Symfony\Component\Finder\Adapter\GnuFindAdapter; +use Symfony\Component\Finder\Finder; +/** + * @group legacy + */ class GnuFinderTest extends FinderTest { - protected function getAdapter() + protected function buildFinder() { $adapter = new GnuFindAdapter(); @@ -23,6 +27,8 @@ protected function getAdapter() $this->markTestSkipped(get_class($adapter).' is not supported.'); } - return $adapter; + return Finder::create() + ->removeAdapters() + ->addAdapter($adapter); } } diff --git a/src/Symfony/Component/Finder/Tests/Iterator/FilePathsIteratorTest.php b/src/Symfony/Component/Finder/Tests/Iterator/FilePathsIteratorTest.php index fdf810bebd3db..ab52ccee36c69 100644 --- a/src/Symfony/Component/Finder/Tests/Iterator/FilePathsIteratorTest.php +++ b/src/Symfony/Component/Finder/Tests/Iterator/FilePathsIteratorTest.php @@ -13,6 +13,9 @@ use Symfony\Component\Finder\Iterator\FilePathsIterator; +/** + * @group legacy + */ class FilePathsIteratorTest extends RealIteratorTestCase { /** diff --git a/src/Symfony/Component/Finder/Tests/PhpFinderTest.php b/src/Symfony/Component/Finder/Tests/PhpFinderTest.php new file mode 100644 index 0000000000000..b188340ef3384 --- /dev/null +++ b/src/Symfony/Component/Finder/Tests/PhpFinderTest.php @@ -0,0 +1,45 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Finder\Tests; + +use Symfony\Component\Finder\Adapter\PhpAdapter; +use Symfony\Component\Finder\Finder; + +/** + * @group legacy + */ +class PhpFinderTest extends FinderTest +{ + public function testImplementationsAreSynchronized() + { + $adapterReflector = new \ReflectionMethod('Symfony\Component\Finder\Adapter\PhpAdapter', 'searchInDirectory'); + $finderReflector = new \ReflectionMethod('Symfony\Component\Finder\Finder', 'searchInDirectory'); + + $adapterSource = array_slice(file($adapterReflector->getFileName()), $adapterReflector->getStartLine() + 1, $adapterReflector->getEndLine() - $adapterReflector->getStartLine() - 1); + $adapterSource = implode('', $adapterSource); + $adapterSource = str_replace(array('$this->minDepth', '$this->maxDepth'), array('$minDepth', '$maxDepth'), $adapterSource); + + $finderSource = array_slice(file($finderReflector->getFileName()), $finderReflector->getStartLine() + 1, $finderReflector->getEndLine() - $finderReflector->getStartLine() - 1); + $finderSource = implode('', $finderSource); + + $this->assertStringEndsWith($adapterSource, $finderSource); + } + + protected function buildFinder() + { + $adapter = new PhpAdapter(); + + return Finder::create() + ->removeAdapters() + ->addAdapter($adapter); + } +} diff --git a/src/Symfony/Component/Finder/Tests/Shell/CommandTest.php b/src/Symfony/Component/Finder/Tests/Shell/CommandTest.php index e9145127eaba1..50e20f9b7e876 100644 --- a/src/Symfony/Component/Finder/Tests/Shell/CommandTest.php +++ b/src/Symfony/Component/Finder/Tests/Shell/CommandTest.php @@ -13,6 +13,9 @@ use Symfony\Component\Finder\Shell\Command; +/** + * @group legacy + */ class CommandTest extends \PHPUnit_Framework_TestCase { public function testCreate()