Skip to content

Commit

Permalink
Merge pull request #249 from jenkoian/symlink-support
Browse files Browse the repository at this point in the history
  • Loading branch information
swissspidy authored Jul 5, 2021
2 parents dead2da + 2061f42 commit bf27df3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/IterableCodeExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public static function getFilesFromDirectory( $dir, array $include = [], array $

$files = new RecursiveIteratorIterator(
new RecursiveCallbackFilterIterator(
new RecursiveDirectoryIterator( $dir, RecursiveDirectoryIterator::SKIP_DOTS | RecursiveDirectoryIterator::UNIX_PATHS ),
new RecursiveDirectoryIterator( $dir, RecursiveDirectoryIterator::SKIP_DOTS | RecursiveDirectoryIterator::UNIX_PATHS | RecursiveDirectoryIterator::FOLLOW_SYMLINKS ),
static function ( $file, $key, $iterator ) use ( $include, $exclude, $extensions ) {
/** @var RecursiveCallbackFilterIterator $iterator */
/** @var SplFileInfo $file */
Expand Down
18 changes: 16 additions & 2 deletions tests/IterableCodeExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace WP_CLI\I18n\Tests;

use PHPUnit_Framework_TestCase;
use WP_CLI\I18n\IterableCodeExtractor;
use WP_CLI\Tests\TestCase;
use WP_CLI\Utils;

class IterableCodeExtractorTest extends PHPUnit_Framework_TestCase {
class IterableCodeExtractorTest extends TestCase {

/** @var string A path files are located */
private static $base;
Expand All @@ -23,6 +23,12 @@ public function setUp() {
$property->setAccessible( false );
}

public function tearDown() {
if ( file_exists( self::$base . '/symlinked' ) ) {
unlink( self::$base . '/symlinked' );
}
}

public function test_can_include_files() {
$includes = [ 'foo-plugin', 'bar', 'baz/inc*.js' ];
$result = IterableCodeExtractor::getFilesFromDirectory( self::$base, $includes, [], [ 'php', 'js' ] );
Expand Down Expand Up @@ -176,4 +182,12 @@ public function test_identical_include_exclude() {
$expected = array();
$this->assertEquals( $expected, $result );
}

public function test_can_include_file_in_symlinked_folder() {
symlink( self::$base . '/baz', self::$base . '/symlinked' );
$includes = [ 'symlinked/includes/should_be_included.js' ];
$result = IterableCodeExtractor::getFilesFromDirectory( self::$base, $includes, [], [ 'php', 'js' ] );
$expected = static::$base . 'symlinked/includes/should_be_included.js';
$this->assertContains( $expected, $result );
}
}

0 comments on commit bf27df3

Please sign in to comment.