Skip to content

Commit

Permalink
Fix some windows issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
jails committed Oct 6, 2016
1 parent e3118b4 commit d387865
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 36 deletions.
52 changes: 29 additions & 23 deletions spec/Suite/Dir/Dir.spec.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

$this->normalize = function ($path) {
if (!is_array($path)) {
return str_replace('/', DIRECTORY_SEPARATOR, $path);
return str_replace(DS, '/', $path);
}
$result = [];
foreach ($path as $p) {
Expand All @@ -34,7 +34,7 @@
'type' => 'file',
'recursive' => false
]);
expect($files)->toBe($this->normalize(['spec/Fixture/Dir/file1.txt']));
expect($this->normalize($files))->toBe(['spec/Fixture/Dir/file1.txt']);

});

Expand All @@ -45,102 +45,106 @@
'recursive' => false
]);

expect($sort($files))->toBe($sort($this->normalize([
expect($this->normalize($sort($files)))->toBe($sort([
'spec/Fixture/Dir/.',
'spec/Fixture/Dir/..',
'spec/Fixture/Dir/file1.txt',
'spec/Fixture/Dir/Nested',
'spec/Fixture/Dir/Extensions'
])));
]));

});

it("scans and follow symlinks", function () use ($sort) {

$files = Dir::scan($this->path . DIRECTORY_SEPARATOR . 'Extensions', [
$files = Dir::scan($this->path . DS . 'Extensions', [
'followSymlinks' => false,
'recursive' => false
]);

expect($sort($files))->toBe($this->normalize([
expect($this->normalize($sort($files)))->toBe([
'spec/Fixture/Dir/Extensions/Childs',
'spec/Fixture/Dir/Extensions/file.xml',
'spec/Fixture/Dir/Extensions/index.html',
'spec/Fixture/Dir/Extensions/index.php'
]));
]);

});

it("scans files recursively", function () use ($sort) {

$files = Dir::scan($this->path . DIRECTORY_SEPARATOR . 'Nested', [
$files = Dir::scan($this->path . DS . 'Nested', [
'type' => 'file'
]);

expect($sort($files))->toBe($this->normalize([
expect($this->normalize($sort($files)))->toBe([
'spec/Fixture/Dir/Nested/Childs/child1.txt',
'spec/Fixture/Dir/Nested/nested_file1.txt',
'spec/Fixture/Dir/Nested/nested_file2.txt'
]));
]);

});

it("scans files & directores recursively", function () use ($sort) {

$files = Dir::scan($this->path . DIRECTORY_SEPARATOR . 'Nested');
$files = Dir::scan($this->path . DS . 'Nested');

expect($sort($files))->toBe($this->normalize([
expect($this->normalize($sort($files)))->toBe([
'spec/Fixture/Dir/Nested/Childs',
'spec/Fixture/Dir/Nested/Childs/child1.txt',
'spec/Fixture/Dir/Nested/nested_file1.txt',
'spec/Fixture/Dir/Nested/nested_file2.txt'
]));
]);

});

it("scans only leaves recursively", function () use ($sort) {

$files = Dir::scan($this->path. DIRECTORY_SEPARATOR . 'Nested', [
$files = Dir::scan($this->path. DS . 'Nested', [
'leavesOnly' => true
]);

expect($sort($files))->toBe($this->normalize([
expect($this->normalize($sort($files)))->toBe([
'spec/Fixture/Dir/Nested/Childs/child1.txt',
'spec/Fixture/Dir/Nested/nested_file1.txt',
'spec/Fixture/Dir/Nested/nested_file2.txt'
]));
]);

});

it("scans txt files recursively", function () use ($sort) {

skipIf(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN');

$files = Dir::scan($this->path, [
'include' => '*.txt',
'type' => 'file'
]);

expect($sort($files))->toBe($this->normalize([
expect($this->normalize($sort($files)))->toBe([
'spec/Fixture/Dir/Extensions/Childs/child1.txt',
'spec/Fixture/Dir/Nested/Childs/child1.txt',
'spec/Fixture/Dir/Nested/nested_file1.txt',
'spec/Fixture/Dir/Nested/nested_file2.txt',
'spec/Fixture/Dir/file1.txt'
]));
]);

});

it("scans non nested txt files recursively", function () use ($sort) {

skipIf(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN');

$files = Dir::scan($this->path, [
'include' => '*.txt',
'exclude' => '*Nested*',
'type' => 'file'
]);

expect($sort($files))->toBe($this->normalize([
expect($this->normalize($sort($files)))->toBe([
'spec/Fixture/Dir/Extensions/Childs/child1.txt',
'spec/Fixture/Dir/file1.txt'
]));
]);

});

Expand All @@ -163,7 +167,7 @@
'exclude' => '*nested*',
'type' => 'file'
]);
expect($files)->toBe($this->normalize(['spec/Fixture/Dir/file1.txt']));
expect($this->normalize($files))->toBe(['spec/Fixture/Dir/file1.txt']);

});

Expand Down Expand Up @@ -200,7 +204,7 @@

foreach ($paths as $path) {
$target = preg_replace('~^spec/Fixture~', '', $path);
if ($target === $this->normalize('/Dir/Extensions/Childs/child1.txt')) {
if ($this->normalize($target) === '/Dir/Extensions/Childs/child1.txt') {
expect(file_exists($this->tmpDir . $target))->toBe(false);
} else {
expect(file_exists($this->tmpDir . $target))->toBe(true);
Expand Down Expand Up @@ -258,6 +262,8 @@

it("creates a nested directory", function () {

skipIf(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN');

$path = $this->tmpDir . '/My/Nested/Directory';
$actual = Dir::make($path);
expect($actual)->toBe(true);
Expand Down Expand Up @@ -309,7 +315,7 @@

$temp = sys_get_temp_dir();

expect($dir)->toMatch('~' . $temp . '/spec~');
expect($this->normalize($dir))->toMatch('~' . $this->normalize($temp) . '/spe~');

Dir::remove($dir);

Expand Down
6 changes: 3 additions & 3 deletions spec/Suite/Jit/Interceptor.spec.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@
expect($this->interceptor->loadFile($sourcePath))->toBe(true);
expect(class_exists('loadFileNamespace\ClassB', false))->toBe(true);

$cacheTimestamp = filemtime($this->interceptor->cachePath() . $sourcePath);
$cacheTimestamp = filemtime($this->interceptor->cachePath() . DS . ltrim(preg_replace('~:~', '', $sourcePath), DS));
expect($sourceTimestamp)->toBe($cacheTimestamp - 1);

});
Expand Down Expand Up @@ -370,7 +370,7 @@
expect($this->interceptor->loadFile($this->loadFileNamespacePath . DS . 'ClassC.php'))->toBe(true);
expect(class_exists('loadFileNamespace\ClassC', false))->toBe(true);

$cacheTimestamp = filemtime($this->interceptor->cachePath() . $this->loadFileNamespacePath . DS . 'ClassC.php');
$cacheTimestamp = filemtime($this->interceptor->cachePath() . DS . ltrim(preg_replace('~:~', '', $this->loadFileNamespacePath), DS) . DS . 'ClassC.php');
expect($this->watched1Timestamp)->toBe($cacheTimestamp - 1);

});
Expand Down Expand Up @@ -597,7 +597,7 @@

$path = $this->temp . DS . 'ClassToCache.php';
$cached = $this->interceptor->cache($path, '');
expect($cached)->toBe($this->interceptor->cachePath() . $path);
expect($cached)->toBe($this->interceptor->cachePath() . DS . ltrim(preg_replace('~:~', '', $path), DS));

});

Expand Down
6 changes: 3 additions & 3 deletions spec/Suite/Reporter/Coverage/Exporter/Istanbul.spec.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
{"\/home\/kahlan\/kahlan\/spec\/Fixture\/Reporter\/Coverage\/NoEmptyLine.php":{"path":"\/home\/kahlan\/kahlan\/spec\/Fixture\/Reporter\/Coverage\/NoEmptyLine.php","s":{"1":1,"2":0,"3":1,"4":0},"f":{"1":1},"b":[],"statementMap":{"1":{"start":{"line":8,"column":0},"end":{"line":8,"column":31}},"2":{"start":{"line":10,"column":0},"end":{"line":10,"column":34}},"3":{"start":{"line":12,"column":0},"end":{"line":12,"column":30}},"4":{"start":{"line":13,"column":0},"end":{"line":13,"column":30}}},"fnMap":{"1":{"name":"shallNotPass","line":6,"loc":{"start":{"line":6,"column":0},"end":{"line":14,"column":false}}}},"branchMap":[]}}
EOD;

expect($json)->toBe($expected);
expect(str_replace('\\\\', '\\/', $json))->toBe($expected);
});

it("exports the coverage of a file with an extra line at the end", function () {
Expand Down Expand Up @@ -77,7 +77,7 @@
{"\/home\/kahlan\/kahlan\/spec\/Fixture\/Reporter\/Coverage\/ExtraEmptyLine.php":{"path":"\/home\/kahlan\/kahlan\/spec\/Fixture\/Reporter\/Coverage\/ExtraEmptyLine.php","s":{"1":1,"2":0,"3":1,"4":0},"f":{"1":1},"b":[],"statementMap":{"1":{"start":{"line":8,"column":0},"end":{"line":8,"column":31}},"2":{"start":{"line":10,"column":0},"end":{"line":10,"column":34}},"3":{"start":{"line":12,"column":0},"end":{"line":12,"column":30}},"4":{"start":{"line":13,"column":0},"end":{"line":13,"column":30}}},"fnMap":{"1":{"name":"shallNotPass","line":6,"loc":{"start":{"line":6,"column":0},"end":{"line":14,"column":false}}}},"branchMap":[]}}
EOD;

expect($json)->toBe($expected);
expect(str_replace('\\\\', '\\/', $json))->toBe($expected);

});

Expand Down Expand Up @@ -125,7 +125,7 @@
{"\/home\/kahlan\/kahlan\/spec\/Fixture\/Reporter\/Coverage\/NoEmptyLine.php":{"path":"\/home\/kahlan\/kahlan\/spec\/Fixture\/Reporter\/Coverage\/NoEmptyLine.php","s":{"1":1,"2":0,"3":1,"4":0},"f":{"1":1},"b":[],"statementMap":{"1":{"start":{"line":8,"column":0},"end":{"line":8,"column":31}},"2":{"start":{"line":10,"column":0},"end":{"line":10,"column":34}},"3":{"start":{"line":12,"column":0},"end":{"line":12,"column":30}},"4":{"start":{"line":13,"column":0},"end":{"line":13,"column":30}}},"fnMap":{"1":{"name":"shallNotPass","line":6,"loc":{"start":{"line":6,"column":0},"end":{"line":14,"column":false}}}},"branchMap":[]}}
EOD;

expect($json)->toBe($expected);
expect(str_replace('\\\\', '\\/', $json))->toBe($expected);

});

Expand Down
6 changes: 3 additions & 3 deletions spec/Suite/Reporter/Coverage/Exporter/Lcov.spec.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
end_of_record
EOD;

expect($txt)->toBe($expected);
expect(str_replace(DS, '/', $txt))->toBe($expected);
});

it("exports the coverage of a file with an extra line at the end", function () {
Expand Down Expand Up @@ -100,7 +100,7 @@
LH:2
end_of_record
EOD;
expect($txt)->toBe($expected);
expect(str_replace(DS, '/', $txt))->toBe($expected);

});

Expand Down Expand Up @@ -160,7 +160,7 @@
end_of_record
EOD;

expect($txt)->toBe($expected);
expect(str_replace(DS, '/', $txt))->toBe($expected);

});

Expand Down
2 changes: 1 addition & 1 deletion src/Dir/Dir.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ protected static function _copy($path, $dest, $options)
$paths = static::scan($path, $options);

foreach ($paths as $path) {
$target = preg_replace('~^' . $root . '~', '', $path);
$target = preg_replace('~^' . preg_quote(rtrim($root, $ds)) . '~', '', $path);
if (is_dir($path)) {
mkdir($dest . $ds . ltrim($target, $ds), $options['mode'], true);
} else {
Expand Down
5 changes: 2 additions & 3 deletions src/Jit/Interceptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -479,11 +479,10 @@ public function cache($file, $content, $timestamp = null)
*/
public function cached($file)
{
if (!$cache = $this->cachePath()) {
if (!$cachePath = $this->cachePath()) {
return false;
}

$path = $cache . DS . ltrim($file, DS);
$path = $cachePath . DS . ltrim(preg_replace('~:~', '', $file), DS);

if (!@file_exists($path)) {
return false;
Expand Down

0 comments on commit d387865

Please sign in to comment.