2022-02-23 15:58:18 +00:00
|
|
|
<?php declare(strict_types=1);
|
2011-12-03 19:44:00 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of Composer.
|
|
|
|
*
|
|
|
|
* (c) Nils Adermann <naderman@naderman.de>
|
|
|
|
* Jordi Boggiano <j.boggiano@seld.be>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2012-02-28 10:59:18 +00:00
|
|
|
namespace Composer\Test\Util;
|
2011-12-03 19:44:00 +00:00
|
|
|
|
2023-07-21 08:58:54 +00:00
|
|
|
use Composer\Util\Platform;
|
2012-02-09 17:45:28 +00:00
|
|
|
use Composer\Util\Filesystem;
|
2018-11-12 14:23:32 +00:00
|
|
|
use Composer\Test\TestCase;
|
2011-12-03 19:44:00 +00:00
|
|
|
|
|
|
|
class FilesystemTest extends TestCase
|
|
|
|
{
|
2015-12-14 14:35:27 +00:00
|
|
|
/**
|
|
|
|
* @var Filesystem
|
|
|
|
*/
|
|
|
|
private $fs;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $workingDir;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $testFile;
|
|
|
|
|
2021-12-08 16:03:05 +00:00
|
|
|
public function setUp(): void
|
2015-12-14 14:35:27 +00:00
|
|
|
{
|
|
|
|
$this->fs = new Filesystem;
|
2022-05-11 14:05:35 +00:00
|
|
|
$this->workingDir = self::getUniqueTmpDirectory();
|
|
|
|
$this->testFile = self::getUniqueTmpDirectory() . '/composer_test_file';
|
2015-12-14 14:35:27 +00:00
|
|
|
}
|
|
|
|
|
2021-12-09 16:09:07 +00:00
|
|
|
protected function tearDown(): void
|
2015-12-14 14:35:27 +00:00
|
|
|
{
|
2021-12-09 16:09:07 +00:00
|
|
|
parent::tearDown();
|
2015-12-14 14:35:27 +00:00
|
|
|
if (is_dir($this->workingDir)) {
|
|
|
|
$this->fs->removeDirectory($this->workingDir);
|
|
|
|
}
|
|
|
|
if (is_file($this->testFile)) {
|
2016-01-21 12:01:55 +00:00
|
|
|
$this->fs->removeDirectory(dirname($this->testFile));
|
2015-12-14 14:35:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-11 18:36:39 +00:00
|
|
|
/**
|
|
|
|
* @dataProvider providePathCouplesAsCode
|
|
|
|
*/
|
2022-02-22 15:47:09 +00:00
|
|
|
public function testFindShortestPathCode(string $a, string $b, bool $directory, string $expected, bool $static = false): void
|
2016-04-11 18:36:39 +00:00
|
|
|
{
|
|
|
|
$fs = new Filesystem;
|
|
|
|
$this->assertEquals($expected, $fs->findShortestPathCode($a, $b, $directory, $static));
|
|
|
|
}
|
|
|
|
|
2022-11-24 13:39:08 +00:00
|
|
|
public static function providePathCouplesAsCode(): array
|
2011-12-03 19:44:00 +00:00
|
|
|
{
|
2022-08-17 12:20:07 +00:00
|
|
|
return [
|
|
|
|
['/foo/bar', '/foo/bar', false, "__FILE__"],
|
|
|
|
['/foo/bar', '/foo/baz', false, "__DIR__.'/baz'"],
|
|
|
|
['/foo/bin/run', '/foo/vendor/acme/bin/run', false, "dirname(__DIR__).'/vendor/acme/bin/run'"],
|
|
|
|
['/foo/bin/run', '/bar/bin/run', false, "'/bar/bin/run'"],
|
|
|
|
['c:/bin/run', 'c:/vendor/acme/bin/run', false, "dirname(__DIR__).'/vendor/acme/bin/run'"],
|
|
|
|
['c:\\bin\\run', 'c:/vendor/acme/bin/run', false, "dirname(__DIR__).'/vendor/acme/bin/run'"],
|
|
|
|
['c:/bin/run', 'D:/vendor/acme/bin/run', false, "'D:/vendor/acme/bin/run'"],
|
|
|
|
['c:\\bin\\run', 'd:/vendor/acme/bin/run', false, "'D:/vendor/acme/bin/run'"],
|
|
|
|
['/foo/bar', '/foo/bar', true, "__DIR__"],
|
|
|
|
['/foo/bar/', '/foo/bar', true, "__DIR__"],
|
2022-11-10 15:32:18 +00:00
|
|
|
['/foo', '/baz', true, "dirname(__DIR__).'/baz'"],
|
2022-08-17 12:20:07 +00:00
|
|
|
['/foo/bar', '/foo/baz', true, "dirname(__DIR__).'/baz'"],
|
|
|
|
['/foo/bin/run', '/foo/vendor/acme/bin/run', true, "dirname(dirname(__DIR__)).'/vendor/acme/bin/run'"],
|
|
|
|
['/foo/bin/run', '/bar/bin/run', true, "'/bar/bin/run'"],
|
|
|
|
['/bin/run', '/bin/run', true, "__DIR__"],
|
|
|
|
['c:/bin/run', 'C:\\bin/run', true, "__DIR__"],
|
|
|
|
['c:/bin/run', 'c:/vendor/acme/bin/run', true, "dirname(dirname(__DIR__)).'/vendor/acme/bin/run'"],
|
|
|
|
['c:\\bin\\run', 'c:/vendor/acme/bin/run', true, "dirname(dirname(__DIR__)).'/vendor/acme/bin/run'"],
|
|
|
|
['c:/bin/run', 'd:/vendor/acme/bin/run', true, "'D:/vendor/acme/bin/run'"],
|
|
|
|
['c:\\bin\\run', 'd:/vendor/acme/bin/run', true, "'D:/vendor/acme/bin/run'"],
|
|
|
|
['C:/Temp/test', 'C:\Temp', true, "dirname(__DIR__)"],
|
|
|
|
['C:/Temp', 'C:\Temp\test', true, "__DIR__ . '/test'"],
|
|
|
|
['/tmp/test', '/tmp', true, "dirname(__DIR__)"],
|
|
|
|
['/tmp', '/tmp/test', true, "__DIR__ . '/test'"],
|
|
|
|
['C:/Temp', 'c:\Temp\test', true, "__DIR__ . '/test'"],
|
|
|
|
['/tmp/test/./', '/tmp/test/', true, '__DIR__'],
|
|
|
|
['/tmp/test/../vendor', '/tmp/test', true, "dirname(__DIR__).'/test'"],
|
|
|
|
['/tmp/test/.././vendor', '/tmp/test', true, "dirname(__DIR__).'/test'"],
|
|
|
|
['C:/Temp', 'c:\Temp\..\..\test', true, "dirname(__DIR__).'/test'"],
|
|
|
|
['C:/Temp/../..', 'd:\Temp\..\..\test', true, "'D:/test'"],
|
|
|
|
['/foo/bar', '/foo/bar_vendor', true, "dirname(__DIR__).'/bar_vendor'"],
|
|
|
|
['/foo/bar_vendor', '/foo/bar', true, "dirname(__DIR__).'/bar'"],
|
|
|
|
['/foo/bar_vendor', '/foo/bar/src', true, "dirname(__DIR__).'/bar/src'"],
|
|
|
|
['/foo/bar_vendor/src2', '/foo/bar/src/lib', true, "dirname(dirname(__DIR__)).'/bar/src/lib'"],
|
2016-04-11 18:36:39 +00:00
|
|
|
|
|
|
|
// static use case
|
2022-08-17 12:20:07 +00:00
|
|
|
['/tmp/test/../vendor', '/tmp/test', true, "__DIR__ . '/..'.'/test'", true],
|
|
|
|
['/tmp/test/.././vendor', '/tmp/test', true, "__DIR__ . '/..'.'/test'", true],
|
|
|
|
['C:/Temp', 'c:\Temp\..\..\test', true, "__DIR__ . '/..'.'/test'", true],
|
|
|
|
['C:/Temp/../..', 'd:\Temp\..\..\test', true, "'D:/test'", true],
|
|
|
|
['/foo/bar', '/foo/bar_vendor', true, "__DIR__ . '/..'.'/bar_vendor'", true],
|
|
|
|
['/foo/bar_vendor', '/foo/bar', true, "__DIR__ . '/..'.'/bar'", true],
|
|
|
|
['/foo/bar_vendor', '/foo/bar/src', true, "__DIR__ . '/..'.'/bar/src'", true],
|
|
|
|
['/foo/bar_vendor/src2', '/foo/bar/src/lib', true, "__DIR__ . '/../..'.'/bar/src/lib'", true],
|
|
|
|
];
|
2011-12-03 19:44:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providePathCouples
|
|
|
|
*/
|
2022-02-22 15:47:09 +00:00
|
|
|
public function testFindShortestPath(string $a, string $b, string $expected, bool $directory = false): void
|
2011-12-03 19:44:00 +00:00
|
|
|
{
|
|
|
|
$fs = new Filesystem;
|
2012-03-23 11:49:29 +00:00
|
|
|
$this->assertEquals($expected, $fs->findShortestPath($a, $b, $directory));
|
2011-12-03 19:44:00 +00:00
|
|
|
}
|
|
|
|
|
2022-11-24 13:39:08 +00:00
|
|
|
public static function providePathCouples(): array
|
2011-12-03 19:44:00 +00:00
|
|
|
{
|
2022-08-17 12:20:07 +00:00
|
|
|
return [
|
|
|
|
['/foo/bar', '/foo/bar', "./bar"],
|
|
|
|
['/foo/bar', '/foo/baz', "./baz"],
|
|
|
|
['/foo/bar/', '/foo/baz', "./baz"],
|
|
|
|
['/foo/bar', '/foo/bar', "./", true],
|
|
|
|
['/foo/bar', '/foo/baz', "../baz", true],
|
|
|
|
['/foo/bar/', '/foo/baz', "../baz", true],
|
|
|
|
['C:/foo/bar/', 'c:/foo/baz', "../baz", true],
|
|
|
|
['/foo/bin/run', '/foo/vendor/acme/bin/run', "../vendor/acme/bin/run"],
|
|
|
|
['/foo/bin/run', '/bar/bin/run', "/bar/bin/run"],
|
|
|
|
['/foo/bin/run', '/bar/bin/run', "/bar/bin/run", true],
|
|
|
|
['c:/foo/bin/run', 'd:/bar/bin/run', "D:/bar/bin/run", true],
|
|
|
|
['c:/bin/run', 'c:/vendor/acme/bin/run', "../vendor/acme/bin/run"],
|
|
|
|
['c:\\bin\\run', 'c:/vendor/acme/bin/run', "../vendor/acme/bin/run"],
|
|
|
|
['c:/bin/run', 'd:/vendor/acme/bin/run', "D:/vendor/acme/bin/run"],
|
|
|
|
['c:\\bin\\run', 'd:/vendor/acme/bin/run', "D:/vendor/acme/bin/run"],
|
|
|
|
['C:/Temp/test', 'C:\Temp', "./"],
|
|
|
|
['/tmp/test', '/tmp', "./"],
|
|
|
|
['C:/Temp/test/sub', 'C:\Temp', "../"],
|
|
|
|
['/tmp/test/sub', '/tmp', "../"],
|
|
|
|
['/tmp/test/sub', '/tmp', "../../", true],
|
|
|
|
['c:/tmp/test/sub', 'c:/tmp', "../../", true],
|
|
|
|
['/tmp', '/tmp/test', "test"],
|
|
|
|
['C:/Temp', 'C:\Temp\test', "test"],
|
|
|
|
['C:/Temp', 'c:\Temp\test', "test"],
|
|
|
|
['/tmp/test/./', '/tmp/test', './', true],
|
|
|
|
['/tmp/test/../vendor', '/tmp/test', '../test', true],
|
|
|
|
['/tmp/test/.././vendor', '/tmp/test', '../test', true],
|
|
|
|
['C:/Temp', 'c:\Temp\..\..\test', "../test", true],
|
|
|
|
['C:/Temp/../..', 'c:\Temp\..\..\test', "./test", true],
|
|
|
|
['C:/Temp/../..', 'D:\Temp\..\..\test', "D:/test", true],
|
2022-11-10 15:32:18 +00:00
|
|
|
['/tmp', '/tmp/../../test', '../test', true],
|
|
|
|
['/tmp', '/test', '../test', true],
|
2022-08-17 12:20:07 +00:00
|
|
|
['/foo/bar', '/foo/bar_vendor', '../bar_vendor', true],
|
|
|
|
['/foo/bar_vendor', '/foo/bar', '../bar', true],
|
|
|
|
['/foo/bar_vendor', '/foo/bar/src', '../bar/src', true],
|
|
|
|
['/foo/bar_vendor/src2', '/foo/bar/src/lib', '../../bar/src/lib', true],
|
|
|
|
['C:/', 'C:/foo/bar/', "foo/bar", true],
|
|
|
|
];
|
2011-12-03 19:44:00 +00:00
|
|
|
}
|
2012-11-19 09:29:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @group GH-1339
|
|
|
|
*/
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testRemoveDirectoryPhp(): void
|
2012-11-19 09:29:32 +00:00
|
|
|
{
|
2015-12-14 14:35:27 +00:00
|
|
|
@mkdir($this->workingDir . "/level1/level2", 0777, true);
|
|
|
|
file_put_contents($this->workingDir . "/level1/level2/hello.txt", "hello world");
|
2012-11-19 09:29:32 +00:00
|
|
|
|
|
|
|
$fs = new Filesystem;
|
2015-12-14 14:35:27 +00:00
|
|
|
$this->assertTrue($fs->removeDirectoryPhp($this->workingDir));
|
2020-09-11 09:27:26 +00:00
|
|
|
$this->assertFileDoesNotExist($this->workingDir . "/level1/level2/hello.txt");
|
2012-11-19 09:29:32 +00:00
|
|
|
}
|
2012-12-16 19:04:39 +00:00
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testFileSize(): void
|
2012-12-16 19:04:39 +00:00
|
|
|
{
|
2015-12-14 14:35:27 +00:00
|
|
|
file_put_contents($this->testFile, 'Hello');
|
2012-12-16 19:04:39 +00:00
|
|
|
|
|
|
|
$fs = new Filesystem;
|
2015-12-14 14:35:27 +00:00
|
|
|
$this->assertGreaterThanOrEqual(5, $fs->size($this->testFile));
|
2012-12-16 19:04:39 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testDirectorySize(): void
|
2012-12-16 19:04:39 +00:00
|
|
|
{
|
2015-12-14 14:35:27 +00:00
|
|
|
@mkdir($this->workingDir, 0777, true);
|
|
|
|
file_put_contents($this->workingDir."/file1.txt", 'Hello');
|
|
|
|
file_put_contents($this->workingDir."/file2.txt", 'World');
|
2012-12-16 19:04:39 +00:00
|
|
|
|
|
|
|
$fs = new Filesystem;
|
2015-12-14 14:35:27 +00:00
|
|
|
$this->assertGreaterThanOrEqual(10, $fs->size($this->workingDir));
|
2012-12-16 19:04:39 +00:00
|
|
|
}
|
2013-04-03 17:28:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider provideNormalizedPaths
|
|
|
|
*/
|
2022-02-22 15:47:09 +00:00
|
|
|
public function testNormalizePath(string $expected, string $actual): void
|
2013-04-03 17:28:06 +00:00
|
|
|
{
|
|
|
|
$fs = new Filesystem;
|
|
|
|
$this->assertEquals($expected, $fs->normalizePath($actual));
|
|
|
|
}
|
|
|
|
|
2022-11-24 13:39:08 +00:00
|
|
|
public static function provideNormalizedPaths(): array
|
2013-04-03 17:28:06 +00:00
|
|
|
{
|
2022-08-17 12:20:07 +00:00
|
|
|
return [
|
|
|
|
['../foo', '../foo'],
|
|
|
|
['C:/foo/bar', 'c:/foo//bar'],
|
|
|
|
['C:/foo/bar', 'C:/foo/./bar'],
|
|
|
|
['C:/foo/bar', 'C://foo//bar'],
|
|
|
|
['C:/foo/bar', 'C:///foo//bar'],
|
|
|
|
['C:/bar', 'C:/foo/../bar'],
|
|
|
|
['/bar', '/foo/../bar/'],
|
|
|
|
['phar://C:/Foo', 'phar://c:/Foo/Bar/..'],
|
|
|
|
['phar://C:/Foo', 'phar://c:///Foo/Bar/..'],
|
|
|
|
['phar://C:/', 'phar://c:/Foo/Bar/../../../..'],
|
|
|
|
['/', '/Foo/Bar/../../../..'],
|
|
|
|
['/', '/'],
|
|
|
|
['/', '//'],
|
|
|
|
['/', '///'],
|
|
|
|
['/Foo', '///Foo'],
|
|
|
|
['C:/', 'c:\\'],
|
|
|
|
['../src', 'Foo/Bar/../../../src'],
|
|
|
|
['C:../b', 'c:.\\..\\a\\..\\b'],
|
|
|
|
['phar://C:../Foo', 'phar://c:../Foo'],
|
|
|
|
['//foo/bar', '\\\\foo\\bar'],
|
|
|
|
];
|
2013-04-03 17:28:06 +00:00
|
|
|
}
|
2014-07-24 12:17:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @link https://github.com/composer/composer/issues/3157
|
2015-04-21 00:15:28 +00:00
|
|
|
* @requires function symlink
|
2014-07-24 12:17:42 +00:00
|
|
|
*/
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testUnlinkSymlinkedDirectory(): void
|
2014-07-24 12:17:42 +00:00
|
|
|
{
|
2017-03-08 14:07:29 +00:00
|
|
|
$basepath = $this->workingDir;
|
2014-07-24 12:17:42 +00:00
|
|
|
$symlinked = $basepath . "/linked";
|
|
|
|
@mkdir($basepath . "/real", 0777, true);
|
|
|
|
touch($basepath . "/real/FILE");
|
|
|
|
|
|
|
|
$result = @symlink($basepath . "/real", $symlinked);
|
|
|
|
|
|
|
|
if (!$result) {
|
|
|
|
$this->markTestSkipped('Symbolic links for directories not supported on this platform');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_dir($symlinked)) {
|
|
|
|
$this->fail('Precondition assertion failed (is_dir is false on symbolic link to directory).');
|
|
|
|
}
|
|
|
|
|
2017-03-08 14:07:29 +00:00
|
|
|
$fs = new Filesystem();
|
2014-07-24 12:17:42 +00:00
|
|
|
$result = $fs->unlink($symlinked);
|
|
|
|
$this->assertTrue($result);
|
2020-09-11 09:27:26 +00:00
|
|
|
$this->assertFileDoesNotExist($symlinked);
|
2014-07-24 12:17:42 +00:00
|
|
|
}
|
2014-07-24 12:42:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @link https://github.com/composer/composer/issues/3144
|
2015-04-21 00:15:28 +00:00
|
|
|
* @requires function symlink
|
2014-07-24 12:42:37 +00:00
|
|
|
*/
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testRemoveSymlinkedDirectoryWithTrailingSlash(): void
|
2014-07-24 12:42:37 +00:00
|
|
|
{
|
2015-12-14 14:35:27 +00:00
|
|
|
@mkdir($this->workingDir . "/real", 0777, true);
|
|
|
|
touch($this->workingDir . "/real/FILE");
|
2017-03-08 14:07:29 +00:00
|
|
|
$symlinked = $this->workingDir . "/linked";
|
2014-07-24 12:42:37 +00:00
|
|
|
$symlinkedTrailingSlash = $symlinked . "/";
|
|
|
|
|
2015-12-14 14:35:27 +00:00
|
|
|
$result = @symlink($this->workingDir . "/real", $symlinked);
|
2014-07-24 12:42:37 +00:00
|
|
|
|
|
|
|
if (!$result) {
|
|
|
|
$this->markTestSkipped('Symbolic links for directories not supported on this platform');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_dir($symlinked)) {
|
|
|
|
$this->fail('Precondition assertion failed (is_dir is false on symbolic link to directory).');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_dir($symlinkedTrailingSlash)) {
|
|
|
|
$this->fail('Precondition assertion failed (is_dir false w trailing slash).');
|
|
|
|
}
|
|
|
|
|
|
|
|
$fs = new Filesystem();
|
|
|
|
|
|
|
|
$result = $fs->removeDirectory($symlinkedTrailingSlash);
|
|
|
|
$this->assertTrue($result);
|
2020-09-11 09:27:26 +00:00
|
|
|
$this->assertFileDoesNotExist($symlinkedTrailingSlash);
|
|
|
|
$this->assertFileDoesNotExist($symlinked);
|
2014-07-24 12:42:37 +00:00
|
|
|
}
|
2016-02-02 22:44:01 +00:00
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testJunctions(): void
|
2016-02-02 22:44:01 +00:00
|
|
|
{
|
|
|
|
@mkdir($this->workingDir . '/real/nesting/testing', 0777, true);
|
|
|
|
$fs = new Filesystem();
|
|
|
|
|
|
|
|
// Non-Windows systems do not support this and will return false on all tests, and an exception on creation
|
|
|
|
if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
|
|
|
|
$this->assertFalse($fs->isJunction($this->workingDir));
|
|
|
|
$this->assertFalse($fs->removeJunction($this->workingDir));
|
2021-12-09 19:55:26 +00:00
|
|
|
self::expectException('LogicException');
|
|
|
|
self::expectExceptionMessage('not available on non-Windows platform');
|
2016-02-02 22:44:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$target = $this->workingDir . '/real/../real/nesting';
|
|
|
|
$junction = $this->workingDir . '/junction';
|
|
|
|
|
|
|
|
// Create and detect junction
|
|
|
|
$fs->junction($target, $junction);
|
2019-10-08 17:12:56 +00:00
|
|
|
$this->assertTrue($fs->isJunction($junction), $junction . ': is a junction');
|
|
|
|
$this->assertFalse($fs->isJunction($target), $target . ': is not a junction');
|
|
|
|
$this->assertTrue($fs->isJunction($target . '/../../junction'), $target . '/../../junction: is a junction');
|
|
|
|
$this->assertFalse($fs->isJunction($junction . '/../real'), $junction . '/../real: is not a junction');
|
|
|
|
$this->assertTrue($fs->isJunction($junction . '/../junction'), $junction . '/../junction: is a junction');
|
2016-02-02 22:44:01 +00:00
|
|
|
|
|
|
|
// Remove junction
|
2022-06-22 12:20:08 +00:00
|
|
|
$this->assertDirectoryExists($junction, $junction . ' is a directory');
|
2019-10-08 17:12:56 +00:00
|
|
|
$this->assertTrue($fs->removeJunction($junction), $junction . ' has been removed');
|
2022-06-22 12:20:08 +00:00
|
|
|
$this->assertDirectoryDoesNotExist($junction, $junction . ' is not a directory');
|
2016-02-02 22:44:01 +00:00
|
|
|
}
|
2017-08-31 14:52:18 +00:00
|
|
|
|
2023-07-21 08:58:54 +00:00
|
|
|
public function testOverrideJunctions(): void
|
|
|
|
{
|
|
|
|
if (!Platform::isWindows()) {
|
|
|
|
$this->markTestSkipped('Only runs on windows');
|
|
|
|
}
|
|
|
|
|
|
|
|
@mkdir($this->workingDir.'/real/nesting/testing', 0777, true);
|
|
|
|
$fs = new Filesystem();
|
|
|
|
|
|
|
|
$old_target = $this->workingDir.'/real/nesting/testing';
|
|
|
|
$target = $this->workingDir.'/real/../real/nesting';
|
|
|
|
$junction = $this->workingDir.'/junction';
|
|
|
|
|
|
|
|
// Override non-broken junction
|
|
|
|
$fs->junction($old_target, $junction);
|
|
|
|
$fs->junction($target, $junction);
|
|
|
|
|
|
|
|
$this->assertTrue($fs->isJunction($junction), $junction.': is a junction');
|
|
|
|
$this->assertTrue($fs->isJunction($target.'/../../junction'), $target.'/../../junction: is a junction');
|
|
|
|
|
|
|
|
//Remove junction
|
|
|
|
$this->assertTrue($fs->removeJunction($junction), $junction . ' has been removed');
|
|
|
|
|
|
|
|
// Override broken junction
|
|
|
|
$fs->junction($old_target, $junction);
|
|
|
|
$fs->removeDirectory($old_target);
|
|
|
|
$fs->junction($target, $junction);
|
|
|
|
|
|
|
|
$this->assertTrue($fs->isJunction($junction), $junction.': is a junction');
|
|
|
|
$this->assertTrue($fs->isJunction($target.'/../../junction'), $target.'/../../junction: is a junction');
|
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testCopy(): void
|
2017-08-31 14:52:18 +00:00
|
|
|
{
|
|
|
|
@mkdir($this->workingDir . '/foo/bar', 0777, true);
|
|
|
|
@mkdir($this->workingDir . '/foo/baz', 0777, true);
|
|
|
|
file_put_contents($this->workingDir . '/foo/foo.file', 'foo');
|
|
|
|
file_put_contents($this->workingDir . '/foo/bar/foobar.file', 'foobar');
|
|
|
|
file_put_contents($this->workingDir . '/foo/baz/foobaz.file', 'foobaz');
|
|
|
|
file_put_contents($this->testFile, 'testfile');
|
2017-09-01 18:47:13 +00:00
|
|
|
|
2017-08-31 14:52:18 +00:00
|
|
|
$fs = new Filesystem();
|
2017-09-01 18:47:13 +00:00
|
|
|
|
2017-08-31 14:52:18 +00:00
|
|
|
$result1 = $fs->copy($this->workingDir . '/foo', $this->workingDir . '/foop');
|
2017-12-18 15:02:48 +00:00
|
|
|
$this->assertTrue($result1, 'Copying directory failed.');
|
2022-06-22 12:20:08 +00:00
|
|
|
$this->assertDirectoryExists($this->workingDir . '/foop', 'Not a directory: ' . $this->workingDir . '/foop');
|
|
|
|
$this->assertDirectoryExists($this->workingDir . '/foop/bar', 'Not a directory: ' . $this->workingDir . '/foop/bar');
|
|
|
|
$this->assertDirectoryExists($this->workingDir . '/foop/baz', 'Not a directory: ' . $this->workingDir . '/foop/baz');
|
|
|
|
$this->assertFileExists($this->workingDir . '/foop/foo.file', 'Not a file: ' . $this->workingDir . '/foop/foo.file');
|
|
|
|
$this->assertFileExists($this->workingDir . '/foop/bar/foobar.file', 'Not a file: ' . $this->workingDir . '/foop/bar/foobar.file');
|
|
|
|
$this->assertFileExists($this->workingDir . '/foop/baz/foobaz.file', 'Not a file: ' . $this->workingDir . '/foop/baz/foobaz.file');
|
2017-09-01 18:47:13 +00:00
|
|
|
|
|
|
|
$result2 = $fs->copy($this->testFile, $this->workingDir . '/testfile.file');
|
2017-08-31 14:52:18 +00:00
|
|
|
$this->assertTrue($result2);
|
2022-06-22 12:20:08 +00:00
|
|
|
$this->assertFileExists($this->workingDir . '/testfile.file');
|
2017-08-31 14:52:18 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testCopyThenRemove(): void
|
2017-08-31 14:52:18 +00:00
|
|
|
{
|
|
|
|
@mkdir($this->workingDir . '/foo/bar', 0777, true);
|
|
|
|
@mkdir($this->workingDir . '/foo/baz', 0777, true);
|
|
|
|
file_put_contents($this->workingDir . '/foo/foo.file', 'foo');
|
|
|
|
file_put_contents($this->workingDir . '/foo/bar/foobar.file', 'foobar');
|
|
|
|
file_put_contents($this->workingDir . '/foo/baz/foobaz.file', 'foobaz');
|
|
|
|
file_put_contents($this->testFile, 'testfile');
|
2017-09-01 18:47:13 +00:00
|
|
|
|
2017-08-31 14:52:18 +00:00
|
|
|
$fs = new Filesystem();
|
2017-09-01 18:47:13 +00:00
|
|
|
|
|
|
|
$fs->copyThenRemove($this->testFile, $this->workingDir . '/testfile.file');
|
2022-06-22 12:20:08 +00:00
|
|
|
$this->assertFileDoesNotExist($this->testFile, 'Still a file: ' . $this->testFile);
|
2017-09-01 18:47:13 +00:00
|
|
|
|
2017-08-31 14:52:18 +00:00
|
|
|
$fs->copyThenRemove($this->workingDir . '/foo', $this->workingDir . '/foop');
|
2022-06-22 12:20:08 +00:00
|
|
|
$this->assertFileDoesNotExist($this->workingDir . '/foo/baz/foobaz.file', 'Still a file: ' . $this->workingDir . '/foo/baz/foobaz.file');
|
|
|
|
$this->assertFileDoesNotExist($this->workingDir . '/foo/bar/foobar.file', 'Still a file: ' . $this->workingDir . '/foo/bar/foobar.file');
|
|
|
|
$this->assertFileDoesNotExist($this->workingDir . '/foo/foo.file', 'Still a file: ' . $this->workingDir . '/foo/foo.file');
|
|
|
|
$this->assertDirectoryDoesNotExist($this->workingDir . '/foo/baz', 'Still a directory: ' . $this->workingDir . '/foo/baz');
|
|
|
|
$this->assertDirectoryDoesNotExist($this->workingDir . '/foo/bar', 'Still a directory: ' . $this->workingDir . '/foo/bar');
|
|
|
|
$this->assertDirectoryDoesNotExist($this->workingDir . '/foo', 'Still a directory: ' . $this->workingDir . '/foo');
|
2017-08-31 14:52:18 +00:00
|
|
|
}
|
2011-12-03 19:44:00 +00:00
|
|
|
}
|