Skip to content

Commit 9266608

Browse files
committed
Merge branch '4.0'
* 4.0: fixed tests [Finder] Remove duplicate slashes in filenames [VarDumper] Skip some tests on custom xdebug.file_link_format [WebProfilerBundle][HttpKernel] Make FileLinkFormatter URL format generation lazy bumped Symfony version to 4.0.8 updated VERSION for 4.0.7 updated CHANGELOG for 4.0.7 bumped Symfony version to 3.4.8 updated VERSION for 3.4.7 updated CHANGELOG for 3.4.7
2 parents 5d6a679 + f8e4982 commit 9266608

File tree

3 files changed

+47
-10
lines changed

3 files changed

+47
-10
lines changed

Finder.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,9 +540,9 @@ public function in($dirs)
540540

541541
foreach ((array) $dirs as $dir) {
542542
if (is_dir($dir)) {
543-
$resolvedDirs[] = $dir;
543+
$resolvedDirs[] = $this->normalizeDir($dir);
544544
} elseif ($glob = glob($dir, (defined('GLOB_BRACE') ? GLOB_BRACE : 0) | GLOB_ONLYDIR)) {
545-
$resolvedDirs = array_merge($resolvedDirs, $glob);
545+
$resolvedDirs = array_merge($resolvedDirs, array_map(array($this, 'normalizeDir'), $glob));
546546
} else {
547547
throw new \InvalidArgumentException(sprintf('The "%s" directory does not exist.', $dir));
548548
}
@@ -723,4 +723,16 @@ private function searchInDirectory(string $dir): \Iterator
723723

724724
return $iterator;
725725
}
726+
727+
/**
728+
* Normalizes given directory names by removing trailing slashes.
729+
*
730+
* @param string $dir
731+
*
732+
* @return string
733+
*/
734+
private function normalizeDir($dir)
735+
{
736+
return rtrim($dir, '/'.\DIRECTORY_SEPARATOR);
737+
}
726738
}

SplFileInfo.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class SplFileInfo extends \SplFileInfo
2828
*/
2929
public function __construct(string $file, string $relativePath, string $relativePathname)
3030
{
31-
parent::__construct(realpath($file) ?: $file);
31+
parent::__construct($file);
3232
$this->relativePath = $relativePath;
3333
$this->relativePathname = $relativePathname;
3434
}

Tests/FinderTest.php

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,40 @@ public function testFiles()
4848

4949
public function testRemoveTrailingSlash()
5050
{
51-
if ('\\' === \DIRECTORY_SEPARATOR) {
52-
$this->markTestSkipped('This test cannot be run on Windows.');
51+
$finder = $this->buildFinder();
52+
53+
$expected = $this->toAbsolute(array('foo/bar.tmp', 'test.php', 'test.py', 'foo bar'));
54+
$in = self::$tmpDir.'//';
55+
56+
$this->assertIterator($expected, $finder->in($in)->files()->getIterator());
57+
}
58+
59+
public function testSymlinksNotResolved()
60+
{
61+
if ('\\' === DIRECTORY_SEPARATOR) {
62+
$this->markTestSkipped('symlinks are not supported on Windows');
5363
}
5464

5565
$finder = $this->buildFinder();
5666

57-
$expected = $this->toAbsolute(array('foo/bar.tmp', 'test.php', 'test.py', 'foo bar'));
58-
$in = '//'.realpath(self::$tmpDir).'//';
67+
symlink($this->toAbsolute('foo'), $this->toAbsolute('baz'));
68+
$expected = $this->toAbsolute(array('baz/bar.tmp'));
69+
$in = self::$tmpDir.'/baz/';
70+
try {
71+
$this->assertIterator($expected, $finder->in($in)->files()->getIterator());
72+
unlink($this->toAbsolute('baz'));
73+
} catch (\Exception $e) {
74+
unlink($this->toAbsolute('baz'));
75+
throw $e;
76+
}
77+
}
78+
79+
public function testBackPathNotNormalized()
80+
{
81+
$finder = $this->buildFinder();
5982

83+
$expected = $this->toAbsolute(array('foo/../foo/bar.tmp'));
84+
$in = self::$tmpDir.'/foo/../foo/';
6085
$this->assertIterator($expected, $finder->in($in)->files()->getIterator());
6186
}
6287

@@ -275,7 +300,7 @@ public function testInWithNonExistentDirectory()
275300
public function testInWithGlob()
276301
{
277302
$finder = $this->buildFinder();
278-
$finder->in(array(__DIR__.'/Fixtures/*/B/C', __DIR__.'/Fixtures/*/*/B/C'))->getIterator();
303+
$finder->in(array(__DIR__.'/Fixtures/*/B/C/', __DIR__.'/Fixtures/*/*/B/C/'))->getIterator();
279304

280305
$this->assertIterator($this->toAbsoluteFixtures(array('A/B/C/abc.dat', 'copy/A/B/C/abc.dat.copy')), $finder);
281306
}
@@ -528,8 +553,8 @@ public function testMultipleLocationsWithSubDirectories()
528553
$finder->in($locations)->depth('< 10')->name('*.neon');
529554

530555
$expected = array(
531-
__DIR__.DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'one'.DIRECTORY_SEPARATOR.'b'.DIRECTORY_SEPARATOR.'c.neon',
532-
__DIR__.DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'one'.DIRECTORY_SEPARATOR.'b'.DIRECTORY_SEPARATOR.'d.neon',
556+
__DIR__.'/Fixtures/one'.DIRECTORY_SEPARATOR.'b'.DIRECTORY_SEPARATOR.'c.neon',
557+
__DIR__.'/Fixtures/one'.DIRECTORY_SEPARATOR.'b'.DIRECTORY_SEPARATOR.'d.neon',
533558
);
534559

535560
$this->assertIterator($expected, $finder);

0 commit comments

Comments
 (0)