$this->filesystem->copy($sourceFilePath, $targetFilePath);
$this->assertFileExists($targetFilePath);
- $this->assertEquals('SOURCE FILE', file_get_contents($targetFilePath));
+ $this->assertStringEqualsFile($targetFilePath, 'SOURCE FILE');
}
/**
$this->filesystem->copy($sourceFilePath, $targetFilePath);
$this->assertFileExists($targetFilePath);
- $this->assertEquals('SOURCE FILE', file_get_contents($targetFilePath));
+ $this->assertStringEqualsFile($targetFilePath, 'SOURCE FILE');
}
public function testCopyDoesNotOverrideExistingFileByDefault()
$this->filesystem->copy($sourceFilePath, $targetFilePath);
$this->assertFileExists($targetFilePath);
- $this->assertEquals('TARGET FILE', file_get_contents($targetFilePath));
+ $this->assertStringEqualsFile($targetFilePath, 'TARGET FILE');
}
public function testCopyOverridesExistingFileIfForced()
$this->filesystem->copy($sourceFilePath, $targetFilePath, true);
$this->assertFileExists($targetFilePath);
- $this->assertEquals('SOURCE FILE', file_get_contents($targetFilePath));
+ $this->assertStringEqualsFile($targetFilePath, 'SOURCE FILE');
}
/**
$this->assertTrue(is_dir($targetFileDirectory));
$this->assertFileExists($targetFilePath);
- $this->assertEquals('SOURCE FILE', file_get_contents($targetFilePath));
+ $this->assertStringEqualsFile($targetFilePath, 'SOURCE FILE');
}
/**
public function testFilesExistsFails()
{
if ('\\' !== DIRECTORY_SEPARATOR) {
- $this->markTestSkipped('Test covers edge case on Windows only.');
+ $this->markTestSkipped('Long file names are an issue on Windows');
}
-
$basePath = $this->workspace.'\\directory\\';
+ $maxPathLength = PHP_MAXPATHLEN - 2;
$oldPath = getcwd();
mkdir($basePath);
chdir($basePath);
- $file = str_repeat('T', 259 - strlen($basePath));
+ $file = str_repeat('T', $maxPathLength - strlen($basePath) + 1);
$path = $basePath.$file;
exec('TYPE NUL >>'.$file); // equivalent of touch, we can not use the php touch() here because it suffers from the same limitation
$this->longPathNamesWindows[] = $path; // save this so we can clean up later
$this->filesystem->remove($link);
- $this->assertTrue(!is_link($link));
- $this->assertTrue(!is_file($link));
- $this->assertTrue(!is_dir($link));
+ $this->assertFalse(is_link($link));
+ $this->assertFalse(is_file($link));
+ $this->assertFalse(is_dir($link));
}
public function testSymlinkIsOverwrittenIfPointsToDifferentTarget()
$this->assertEquals($expectedPath, $path);
}
- /**
- * @return array
- */
public function providePathsForMakePathRelative()
{
$paths = array(
array('/var/lib/symfony/src/Symfony', '/var/lib/symfony/src/Symfony/Component/', '../'),
array('var/lib/symfony/', 'var/lib/symfony/src/Symfony/Component', '../../../'),
array('/usr/lib/symfony/', '/var/lib/symfony/src/Symfony/Component', '../../../../../../usr/lib/symfony/'),
+ array('usr/lib/symfony/', 'var/lib/symfony/src/Symfony/Component', '../../../../../../usr/lib/symfony/'),
array('/var/lib/symfony/src/Symfony/', '/var/lib/symfony/', 'src/Symfony/'),
array('/aa/bb', '/aa/bb', './'),
array('/aa/bb', '/aa/bb/', './'),
array('C:/aa/bb/../../cc', 'C:/aa/../dd/..', 'cc/'),
array('C:/../aa/bb/cc', 'C:/aa/dd/..', 'bb/cc/'),
array('C:/../../aa/../bb/cc', 'C:/aa/dd/..', '../bb/cc/'),
+ array('aa/bb', 'aa/cc', '../bb/'),
+ array('aa/cc', 'bb/cc', '../../aa/cc/'),
+ array('aa/bb', 'aa/./cc', '../bb/'),
+ array('aa/./bb', 'aa/cc', '../bb/'),
+ array('aa/./bb', 'aa/./cc', '../bb/'),
+ array('../../', '../../', './'),
+ array('../aa/bb/', 'aa/bb/', '../../../aa/bb/'),
+ array('../../../', '../../', '../'),
+ array('', '', './'),
+ array('', 'aa/', '../'),
+ array('aa/', '', 'aa/'),
);
if ('\\' === DIRECTORY_SEPARATOR) {
$this->assertEquals('\\' === DIRECTORY_SEPARATOR ? realpath($sourcePath.'\nested') : 'nested', readlink($targetPath.DIRECTORY_SEPARATOR.'link1'));
}
+ public function testMirrorContentsWithSameNameAsSourceOrTargetWithoutDeleteOption()
+ {
+ $sourcePath = $this->workspace.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR;
+
+ mkdir($sourcePath);
+ touch($sourcePath.'source');
+ touch($sourcePath.'target');
+
+ $targetPath = $this->workspace.DIRECTORY_SEPARATOR.'target'.DIRECTORY_SEPARATOR;
+
+ $oldPath = getcwd();
+ chdir($this->workspace);
+
+ $this->filesystem->mirror('source', $targetPath);
+
+ chdir($oldPath);
+
+ $this->assertTrue(is_dir($targetPath));
+ $this->assertFileExists($targetPath.'source');
+ $this->assertFileExists($targetPath.'target');
+ }
+
+ public function testMirrorContentsWithSameNameAsSourceOrTargetWithDeleteOption()
+ {
+ $sourcePath = $this->workspace.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR;
+
+ mkdir($sourcePath);
+ touch($sourcePath.'source');
+
+ $targetPath = $this->workspace.DIRECTORY_SEPARATOR.'target'.DIRECTORY_SEPARATOR;
+
+ mkdir($targetPath);
+ touch($targetPath.'source');
+ touch($targetPath.'target');
+
+ $oldPath = getcwd();
+ chdir($this->workspace);
+
+ $this->filesystem->mirror('source', 'target', null, array('delete' => true));
+
+ chdir($oldPath);
+
+ $this->assertTrue(is_dir($targetPath));
+ $this->assertFileExists($targetPath.'source');
+ $this->assertFileNotExists($targetPath.'target');
+ }
+
/**
* @dataProvider providePathsForIsAbsolutePath
*/
$this->assertEquals($expectedResult, $result);
}
- /**
- * @return array
- */
public function providePathsForIsAbsolutePath()
{
return array(
$this->filesystem->dumpFile($filename, 'bar');
$this->assertFileExists($filename);
- $this->assertSame('bar', file_get_contents($filename));
+ $this->assertStringEqualsFile($filename, 'bar');
}
/**
$this->filesystem->dumpFile($filename, 'bar', 0753);
$this->assertFileExists($filename);
- $this->assertSame('bar', file_get_contents($filename));
+ $this->assertStringEqualsFile($filename, 'bar');
// skip mode check on Windows
if ('\\' !== DIRECTORY_SEPARATOR) {
$this->filesystem->dumpFile($filename, 'bar', null);
$this->assertFileExists($filename);
- $this->assertSame('bar', file_get_contents($filename));
+ $this->assertStringEqualsFile($filename, 'bar');
// skip mode check on Windows
if ('\\' !== DIRECTORY_SEPARATOR) {
$this->filesystem->dumpFile($filename, 'bar');
$this->assertFileExists($filename);
- $this->assertSame('bar', file_get_contents($filename));
+ $this->assertStringEqualsFile($filename, 'bar');
}
public function testDumpFileWithFileScheme()