Skip to content

Commit 3578f3b

Browse files
committed
fix(DirectorySnapshot) sort files
1 parent 6324423 commit 3578f3b

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

.github/main.workflow

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
workflow "Test on PHP 5.6" {
2+
on = "push"
3+
resolves = "test"
4+
}
5+
6+
action "install" {
7+
uses = "MilesChou/composer-action/5.6/install@master"
8+
}
9+
10+
action "test" {
11+
needs = ["install"]
12+
uses = "docker://php:5.6-alpine"
13+
args = "vendor/bin/codecept run"
14+
}

src/DirectorySnapshot.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,12 @@ protected function buildIterator($dir)
3636
{
3737
$dir = rtrim($dir, '\\/');
3838

39-
$iterator = new \RecursiveIteratorIterator(
39+
return new \RecursiveIteratorIterator(
4040
new \RecursiveDirectoryIterator(
4141
$dir,
4242
\RecursiveDirectoryIterator::SKIP_DOTS | \RecursiveDirectoryIterator::UNIX_PATHS
4343
)
4444
);
45-
46-
return $iterator;
4745
}
4846

4947
/**
@@ -105,6 +103,8 @@ protected function assertData($data)
105103
return '/' . ltrim(str_replace($root, '', $file->getPathname()), '/');
106104
}, iterator_to_array($currentIterator, false));
107105

106+
usort($currentFiles, 'strcasecmp');
107+
108108
$this->prettyAssert(
109109
$snapshotFiles,
110110
$currentFiles,
@@ -113,7 +113,15 @@ protected function assertData($data)
113113

114114
$multiIterator = new \MultipleIterator();
115115
$multiIterator->attachIterator(new \ArrayIterator($snapshotFiles));
116-
$multiIterator->attachIterator($currentIterator);
116+
$sortedFiles = iterator_to_array($currentIterator);
117+
$sortedFiles = array_combine(
118+
array_map(static function (\SplFileInfo $f) {
119+
return $f->getPathname();
120+
}, $sortedFiles),
121+
$sortedFiles
122+
);
123+
uksort($sortedFiles, 'strcasecmp');
124+
$multiIterator->attachIterator(new \ArrayIterator($sortedFiles));
117125

118126
/** @var \SplFileInfo $file */
119127
foreach ($multiIterator as list($fileRelativePath, $file)) {
@@ -163,6 +171,8 @@ protected function readFileListFromSnapshot($snapshotFilePath)
163171
throw new \RuntimeException("Could not close snapshot file [{$snapshotFilePath}].");
164172
}
165173

174+
usort($filePaths, 'strcasecmp');
175+
166176
return $filePaths;
167177
}
168178

0 commit comments

Comments
 (0)