Merge pull request #884 from snake14/jacobr-finder-files
Changed the Util finder method to force a provided instance of Finder…
This commit is contained in:
commit
4931df2e8f
|
@ -68,7 +68,8 @@ class Util
|
|||
public static function finder($directory, $exclude = null, $pattern = null): Finder
|
||||
{
|
||||
if ($directory instanceof Finder) {
|
||||
return $directory;
|
||||
// Make sure that the provided Finder only finds files and follows symbolic links.
|
||||
return $directory->files()->followLinks();
|
||||
} else {
|
||||
$finder = new Finder();
|
||||
$finder->sortByName();
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
namespace OpenApi\Tests;
|
||||
|
||||
use OpenApi\Util;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
|
||||
class UtilTest extends OpenApiTestCase
|
||||
{
|
||||
|
@ -36,4 +37,19 @@ class UtilTest extends OpenApiTestCase
|
|||
{
|
||||
$this->assertSame('/blogs/{blog_id}/new~posts', Util::refDecode('~1blogs~1{blog_id}~1new~0posts'));
|
||||
}
|
||||
|
||||
public function testFinder()
|
||||
{
|
||||
// Create a finder for one of the example directories that has a subdirectory.
|
||||
$finder = (new Finder())->in(__DIR__.'/../Examples/using-traits');
|
||||
$this->assertGreaterThan(0, iterator_count($finder), 'There should be at least a few files and a directory.');
|
||||
$finder_array = \iterator_to_array($finder);
|
||||
$directory_path = __DIR__.'/../Examples/using-traits/Decoration';
|
||||
$this->assertArrayHasKey($directory_path, $finder_array, 'The directory should be a path in the finder.');
|
||||
// Use the Util method that should set the finder to only find files, since swagger-php only needs files.
|
||||
$finder_result = Util::finder($finder);
|
||||
$this->assertGreaterThan(0, iterator_count($finder_result), 'There should be at least a few file paths.');
|
||||
$finder_result_array = \iterator_to_array($finder_result);
|
||||
$this->assertArrayNotHasKey($directory_path, $finder_result_array, 'The directory should not be a path in the finder.');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue