12
12
namespace Symfony \Component \Finder \Tests ;
13
13
14
14
use Symfony \Component \Finder \Finder ;
15
- use Symfony \Component \Finder \Adapter ;
15
+ use Symfony \Component \Finder \Adapter \ AdapterInterface ;
16
16
17
- class FinderTest extends Iterator \RealIteratorTestCase
17
+ abstract class AbstractFinderTest extends Iterator \RealIteratorTestCase
18
18
{
19
+ abstract protected function getValidAdapters ();
20
+
19
21
public function testCreate ()
20
22
{
21
23
$ this ->assertInstanceOf ('Symfony\Component\Finder\Finder ' , Finder::create ());
@@ -282,7 +284,7 @@ public function testFilter($adapter)
282
284
public function testFollowLinks ($ adapter )
283
285
{
284
286
if ('\\' == DIRECTORY_SEPARATOR ) {
285
- return ;
287
+ $ this -> markTestSkipped ( ' symlinks are not supported on Windows ' ) ;
286
288
}
287
289
288
290
$ finder = $ this ->buildFinder ($ adapter );
@@ -306,7 +308,16 @@ public function testIn($adapter)
306
308
$ finder = $ this ->buildFinder ($ adapter );
307
309
$ iterator = $ finder ->files ()->name ('*.php ' )->depth ('< 1 ' )->in (array (self ::$ tmpDir , __DIR__ ))->getIterator ();
308
310
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 );
310
321
}
311
322
312
323
/**
@@ -519,7 +530,7 @@ public function testContains($adapter, $matchPatterns, $noMatchPatterns, $expect
519
530
/**
520
531
* @dataProvider getAdaptersTestData
521
532
*/
522
- public function testContainsOnDirectory (Adapter \ AdapterInterface $ adapter )
533
+ public function testContainsOnDirectory (AdapterInterface $ adapter )
523
534
{
524
535
$ finder = $ this ->buildFinder ($ adapter );
525
536
$ finder ->in (__DIR__ )
@@ -532,7 +543,7 @@ public function testContainsOnDirectory(Adapter\AdapterInterface $adapter)
532
543
/**
533
544
* @dataProvider getAdaptersTestData
534
545
*/
535
- public function testNotContainsOnDirectory (Adapter \ AdapterInterface $ adapter )
546
+ public function testNotContainsOnDirectory (AdapterInterface $ adapter )
536
547
{
537
548
$ finder = $ this ->buildFinder ($ adapter );
538
549
$ finder ->in (__DIR__ )
@@ -550,7 +561,7 @@ public function testNotContainsOnDirectory(Adapter\AdapterInterface $adapter)
550
561
*
551
562
* @dataProvider getAdaptersTestData
552
563
*/
553
- public function testMultipleLocations (Adapter \ AdapterInterface $ adapter )
564
+ public function testMultipleLocations (AdapterInterface $ adapter )
554
565
{
555
566
$ locations = array (
556
567
self ::$ tmpDir .'/ ' ,
@@ -569,7 +580,7 @@ public function testMultipleLocations(Adapter\AdapterInterface $adapter)
569
580
*
570
581
* @dataProvider getAdaptersTestData
571
582
*/
572
- public function testIteratorKeys (Adapter \ AdapterInterface $ adapter )
583
+ public function testIteratorKeys (AdapterInterface $ adapter )
573
584
{
574
585
$ finder = $ this ->buildFinder ($ adapter )->in (self ::$ tmpDir );
575
586
foreach ($ finder as $ key => $ file ) {
@@ -580,7 +591,7 @@ public function testIteratorKeys(Adapter\AdapterInterface $adapter)
580
591
/**
581
592
* @dataProvider getAdaptersTestData
582
593
*/
583
- public function testRegexSpecialCharsLocationWithPathRestrictionContainingStartFlag (Adapter \ AdapterInterface $ adapter )
594
+ public function testRegexSpecialCharsLocationWithPathRestrictionContainingStartFlag (AdapterInterface $ adapter )
584
595
{
585
596
$ finder = $ this ->buildFinder ($ adapter );
586
597
$ finder ->in (__DIR__ .DIRECTORY_SEPARATOR .'Fixtures ' .DIRECTORY_SEPARATOR .'r+e.gex[c]a(r)s ' )
@@ -603,7 +614,7 @@ public function testAdaptersOrdering()
603
614
604
615
$ this ->assertEquals (
605
616
array ('c ' , 'e ' , 'a ' , 'd ' , 'b ' ),
606
- array_map (function (Adapter \ AdapterInterface $ adapter ) {
617
+ array_map (function (AdapterInterface $ adapter ) {
607
618
return $ adapter ->getName ();
608
619
}, $ finder ->getAdapters ())
609
620
);
@@ -665,7 +676,7 @@ public function getRegexNameTestData()
665
676
/**
666
677
* @dataProvider getTestPathData
667
678
*/
668
- public function testPath (Adapter \ AdapterInterface $ adapter , $ matchPatterns , $ noMatchPatterns , array $ expected )
679
+ public function testPath (AdapterInterface $ adapter , $ matchPatterns , $ noMatchPatterns , array $ expected )
669
680
{
670
681
$ finder = $ this ->buildFinder ($ adapter );
671
682
$ finder ->in (__DIR__ .DIRECTORY_SEPARATOR .'Fixtures ' )
@@ -675,21 +686,6 @@ public function testPath(Adapter\AdapterInterface $adapter, $matchPatterns, $noM
675
686
$ this ->assertIterator ($ this ->toAbsoluteFixtures ($ expected ), $ finder );
676
687
}
677
688
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
-
693
689
public function getTestPathData ()
694
690
{
695
691
$ tests = array (
@@ -740,7 +736,7 @@ public function getTestPathData()
740
736
/**
741
737
* @dataProvider getAdaptersTestData
742
738
*/
743
- public fu
7802
nction testAccessDeniedException (Adapter \ AdapterInterface $ adapter )
739
+ public function testAccessDeniedException (AdapterInterface $ adapter )
744
740
{
745
741
if ('\\' === DIRECTORY_SEPARATOR ) {
746
742
$ this ->markTestSkipped ('chmod is not supported on Windows ' );
@@ -779,7 +775,7 @@ public function testAccessDeniedException(Adapter\AdapterInterface $adapter)
779
775
/**
780
776
* @dataProvider getAdaptersTestData
781
777
*/
782
- public function testIgnoredAccessDeniedException (Adapter \ AdapterInterface $ adapter )
778
+ public function testIgnoredAccessDeniedException (AdapterInterface $ adapter )
783
779
{
784
780
if ('\\' === DIRECTORY_SEPARATOR ) {
785
781
$ this ->markTestSkipped ('chmod is not supported on Windows ' );
@@ -817,27 +813,13 @@ private function buildTestData(array $tests)
817
813
return $ data ;
818
814
}
819
815
820
- private function buildFinder (Adapter \ AdapterInterface $ adapter )
816
+ private function buildFinder (AdapterInterface $ adapter )
821
817
{
822
818
return Finder::create ()
823
819
->removeAdapters ()
824
820
->addAdapter ($ adapter );
825
821
}
826
822
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
-
841
823
/**
842
824
* Searching in multiple locations with sub directories involves
843
825
* AppendIterator which does an unnecessary rewind which leaves
0 commit comments