8000 [Finder] Deprecate find based adapters · symfony/symfony@473330c · GitHub
[go: up one dir, main page]

Skip to content

Commit 473330c

Browse files
[Finder] Deprecate find based adapters
1 parent 7d343e6 commit 473330c

File tree

7 files changed

+128
-48
lines changed

7 files changed

+128
-48
lines changed

src/Symfony/Component/Finder/Adapter/BsdFindAdapter.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\Finder\Adapter;
1313

14+
@trigger_error('The '.__NAMESPACE__.'\BsdFindAdapter class is deprecated since version 2.8 and will be removed in 3.0. Use the PhpAdapter class in the same namespace instead.', E_USER_DEPRECATED);
15+
1416
use Symfony\Component\Finder\Shell\Shell;
1517
use Symfony\Component\Finder\Shell\Command;
1618
use Symfony\Component\Finder\Iterator\SortableIterator;
@@ -20,6 +22,8 @@
2022
* Shell engine implementation using BSD find command.
2123
*
2224
* @author Jean-François Simon <contact@jfsimon.fr>
25+
*
26+
* @deprecated since 2.8, to be removed in 3.0. Use PhpAdapter instead.
2327
*/
2428
class BsdFindAdapter extends AbstractFindAdapter
2529
{

src/Symfony/Component/Finder/Adapter/GnuFindAdapter.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\Finder\Adapter;
1313

14+
@trigger_error('The '.__NAMESPACE__.'\GnuFindAdapter class is deprecated since version 2.8 and will be removed in 3.0. Use the PhpAdapter class in the same namespace instead.', E_USER_DEPRECATED);
15+
1416
use Symfony\Component\Finder\Shell\Shell;
1517
use Symfony\Component\Finder\Shell\Command;
1618
use Symfony\Component\Finder\Iterator\SortableIterator;
@@ -20,6 +22,8 @@
2022
* Shell engine implementation using GNU find command.
2123
*
2224
* @author Jean-François Simon <contact@jfsimon.fr>
25+
*
26+
* @deprecated since 2.8, to be removed in 3.0. Use PhpAdapter instead.
2327
*/
2428
class GnuFindAdapter extends AbstractFindAdapter
2529
{

src/Symfony/Component/Finder/Finder.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
namespace Symfony\Component\Finder;
1313

1414
use Symfony\Component\Finder\Adapter\AdapterInterface;
15-
use Symfony\Component\Finder\Adapter\GnuFindAdapter;
16-
use Symfony\Component\Finder\Adapter\BsdFindAdapter;
1715
use Symfony\Component\Finder\Adapter\PhpAdapter;
1816
use Symfony\Component\Finder\Comparator\DateComparator;
1917
use Symfony\Component\Finder\Comparator\NumberComparator;
@@ -77,9 +75,7 @@ public function __construct()
7775
$this->ignore = static::IGNORE_VCS_FILES | static::IGNORE_DOT_FILES;
7876

7977
$this
80-
->addAdapter(new GnuFindAdapter())
81-
->addAdapter(new BsdFindAdapter())
82-
->addAdapter(new PhpAdapter(), -50)
78+
->addAdapter(new PhpAdapter())
8379
->setAdapter('php')
8480
;
8581
}

src/Symfony/Component/Finder/Tests/FinderTest.php renamed to src/Symfony/Component/Finder/Tests/AbstractFinderTest.php

Lines changed: 25 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
namespace Symfony\Component\Finder\Tests;
1313

1414
use Symfony\Component\Finder\Finder;
15-
use Symfony\Component\Finder\Adapter;
15+
use Symfony\Component\Finder\Adapter\AdapterInterface;
1616

17-
class FinderTest extends Iterator\RealIteratorTestCase
17+
abstract class AbstractFinderTest extends Iterator\RealIteratorTestCase
1818
{
19+
abstract protected function getValidAdapters();
20+
1921
public function testCreate()
2022
{
2123
$this->assertInstanceOf('Symfony\Component\Finder\Finder', Finder::create());
@@ -282,7 +284,7 @@ public function testFilter($adapter)
282284
public function testFollowLinks($adapter)
283285
{
284286
if ('\\' == DIRECTORY_SEPARATOR) {
285-
return;
287+
$this->markTestSkipped('symlinks are not supported on Windows');
286288
}
287289

288290
$finder = $this->buildFinder($adapter);
@@ -306,7 +308,16 @@ public function testIn($adapter)
306308
$finder = $this->buildFinder($adapter);
307309
$iterator = $finder->files()->name('*.php')->depth('< 1')->in(array(self::$tmpDir, __DIR__))->getIterator();
308310

309-
$this->assertIterator(array(self::$tmpDir.DIRECTORY_SEPARATOR.'test.php', __DIR__.DIRECTORY_SEPARATOR.'FinderTest.php', __DIR__.DIRECTORY_SEPARATOR.'GlobTest.php'), $iterator);
311+
$expected = array(
312+
self::$tmpDir.DIRECTORY_SEPARATOR.'test.php',
313+
__DIR__.DIRECTORY_SEPARATOR.'AbstractFinderTest.php',
314+
__DIR__.DIRECTORY_SEPARATOR.'BsdFinderTest.php',
315+
__DIR__.DIRECTORY_SEPARATOR.'GnuFinderTest.php',
316+
__DIR__.DIRECTORY_SEPARATOR.'PhpFinderTest.php',
317+
__DIR__.DIRECTORY_SEPARATOR.'GlobTest.php',
318+
);
319+
320+
$this->assertIterator($expected, $iterator);
310321
}
311322

312323
/**
@@ -519,7 +530,7 @@ public function testContains($adapter, $matchPatterns, $noMatchPatterns, $expect
519530
/**
520531
* @dataProvider getAdaptersTestData
521532
*/
522-
public function testContainsOnDirectory(Adapter\AdapterInterface $adapter)
533+
public function testContainsOnDirectory(AdapterInterface $adapter)
523534
{
524535
$finder = $this->buildFinder($adapter);
525536
$finder->in(__DIR__)
@@ -532,7 +543,7 @@ public function testContainsOnDirectory(Adapter\AdapterInterface $adapter)
532543
/**
533544
* @dataProvider getAdaptersTestData
534545
*/
535-
public function testNotContainsOnDirectory(Adapter\AdapterInterface $adapter)
546+
public function testNotContainsOnDirectory(AdapterInterface $adapter)
536547
{
537548
$finder = $this->buildFinder($adapter);
538549
$finder->in(__DIR__)
@@ -550,7 +561,7 @@ public function testNotContainsOnDirectory(Adapter\AdapterInterface $adapter)
550561
*
551562
* @dataProvider getAdaptersTestData
552563
*/
553-
public function testMultipleLocations(Adapter\AdapterInterface $adapter)
564+
public function testMultipleLocations(AdapterInterface $adapter)
554565
{
555566
$locations = array(
556567
self::$tmpDir.'/',
@@ -569,7 +580,7 @@ public function testMultipleLocations(Adapter\AdapterInterface $adapter)
569580
*
570581
* @dataProvider getAdaptersTestData
571582
*/
572-
public function testIteratorKeys(Adapter\AdapterInterface $adapter)
583+
public function testIteratorKeys(AdapterInterface $adapter)
573584
{
574585
$finder = $this->buildFinder($adapter)->in(self::$tmpDir);
575586
foreach ($finder as $key => $file) {
@@ -580,7 +591,7 @@ public function testIteratorKeys(Adapter\AdapterInterface $adapter)
580591
/**
581592
* @dataProvider getAdaptersTestData
582593
*/
583-
public function testRegexSpecialCharsLocationWithPathRestrictionContainingStartFlag(Adapter\AdapterInterface $adapter)
594+
public function testRegexSpecialCharsLocationWithPathRestrictionContainingStartFlag(AdapterInterface $adapter)
584595
{
585596
$finder = $this->buildFinder($adapter);
586597
$finder->in(__DIR__.DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'r+e.gex[c]a(r)s')
@@ -603,7 +614,7 @@ public function testAdaptersOrdering()
603614

604615
$this->assertEquals(
605616
array('c', 'e', 'a', 'd', 'b'),
606-
array_map(function (Adapter\AdapterInterface $adapter) {
617+
array_map(function (AdapterInterface $adapter) {
607618
return $adapter->getName();
608619
}, $finder->getAdapters())
609620
);
@@ -665,7 +676,7 @@ public function getRegexNameTestData()
665676
/**
666677
* @dataProvider getTestPathData
667678
*/
668-
public function testPath(Adapter\AdapterInterface $adapter, $matchPatterns, $noMatchPatterns, array $expected)
679+
public function testPath(AdapterInterface $adapter, $matchPatterns, $noMatchPatterns, array $expected)
669680
{
670681
$finder = $this->buildFinder($adapter);
671682
$finder->in(__DIR__.DIRECTORY_SEPARATOR.'Fixtures')
@@ -675,21 +686,6 @@ public function testPath(Adapter\AdapterInterface $adapter, $matchPatterns, $noM
675686
$this->assertIterator($this->toAbsoluteFixtures($expected), $finder);
676687
}
677688

678-
public function testAdapterSelection()
679-
{
680-
// test that by default, PhpAdapter is selected
681-
$adapters = Finder::create()->getAdapters();
682-
$this->assertTrue($adapters[0] instanceof Adapter\PhpAdapter);
683-
684-
// test another adapter selection
685-
$adapters = Finder::create()->setAdapter('gnu_find')->getAdapters();
686-
$this->assertTrue($adapters[0] instanceof Adapter\GnuFindAdapter);
687-
688-
// test that useBestAdapter method removes selection
689-
$adapters = Finder::create()->useBestAdapter()->getAdapters();
690-
$this->assertFalse($adapters[0] instanceof Adapter\PhpAdapter);
691-
}
692-
693689
public function getTestPathData()
694690
{
695691
$tests = array(
@@ -740,7 +736,7 @@ public function getTestPathData()
740736
/**
741737
* @dataProvider getAdaptersTestData
742738
*/
743-
public fu 7802 nction testAccessDeniedException(Adapter\AdapterInterface $adapter)
739+
public function testAccessDeniedException(AdapterInterface $adapter)
744740
{
745741
if ('\\' === DIRECTORY_SEPARATOR) {
746742
$this->markTestSkipped('chmod is not supported on Windows');
@@ -779,7 +775,7 @@ public function testAccessDeniedException(Adapter\AdapterInterface $adapter)
779775
/**
780776
* @dataProvider getAdaptersTestData
781777
*/
782-
public function testIgnoredAccessDeniedException(Adapter\AdapterInterface $adapter)
778+
public function testIgnoredAccessDeniedException(AdapterInterface $adapter)
783779
{
784780
if ('\\' === DIRECTORY_SEPARATOR) {
785781
$this->markTestSkipped('chmod is not supported on Windows');
@@ -817,27 +813,13 @@ private function buildTestData(array $tests)
817813
return $data;
818814
}
819815

820-
private function buildFinder(Adapter\AdapterInterface $adapter)
816+
private function buildFinder(AdapterInterface $adapter)
821817
{
822818
return Finder::create()
823819
->removeAdapters()
824820
->addAdapter($adapter);
825821
}
826822

827-
private function getValidAdapters()
828-
{
829-
return array_filter(
830-
array(
831-
new Adapter\BsdFindAdapter(),
832-
new Adapter\GnuFindAdapter(),
833-
new Adapter\PhpAdapter(),
834-
),
835-
function (Adapter\AdapterInterface $adapter) {
836-
return $adapter->isSupported();
837-
}
838-
);
839-
}
840-
841823
/**
842824
* Searching in multiple locations with sub directories involves
843825
* AppendIterator which does an unnecessary rewind which leaves
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Finder\Tests;
13+
14+
use Symfony\Component\Finder\Adapter\BsdFindAdapter;
15+
16+
/**
17+
* @group legacy
18+
*/
19+
class BsdFinderTest extends AbstractFinderTest
20+
{
21+
protected function getValidAdapters()
22+
{
23+
$adapter = new BsdFindAdapter();
24+
25+
if (!$adapter->isSupported()) {
26+
$this->markTestSkipped(get_class($this).' is not supported.');
27+
}
28+
29+
return array($adapter);
30+
}
31+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Finder\Tests;
13+
14+
use Symfony\Component\Finder\Adapter\GnuFindAdapter;
15+
16+
/**
17+
* @group legacy
18+
*/
19+
class GnuFinderTest extends AbstractFinderTest
20+
{
21+
protected function getValidAdapters()
22+
{
23+
$adapter = new GnuFindAdapter();
24+
25+
if (!$adapter->isSupported()) {
26+
$this->markTestSkipped(get_class($this).' is not supported.');
27+
}
28+
29+
return array($adapter);
30+
}
31+
}
Lines changed: 32 additions & 0 deletions
82CA
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Finder\Tests;
13+
14+
use Symfony\Component\Finder\Finder;
15+
use Symfony\Component\Finder\Adapter\PhpAdapter;
16+
17+
class PhpFinderTest extends AbstractFinderTest
18+
{
19+
protected function getValidAdapters()
20+
{
21+
$adapter = new PhpAdapter();
22+
23+
return array($adapter);
24+
}
25+
26+
public function testAdapterSelection()
27+
{
28+
// test that by default, PhpAdapter is selected
29+
$adapters = Finder::create()->getAdapters();
30+
$this->assertTrue($adapters[0] instanceof PhpAdapter);
31+
}
32+
}

0 commit comments

Comments
 (0)
0