1
0
mirror of https://github.com/danog/file.git synced 2024-12-02 09:17:57 +01:00
file/test/FilesystemDriverTest.php

594 lines
17 KiB
PHP
Raw Normal View History

<?php
2015-07-11 03:59:39 +02:00
2015-08-05 16:55:56 +02:00
namespace Amp\File\Test;
2015-07-11 03:59:39 +02:00
use Amp\File;
2019-08-23 20:23:33 +02:00
use Amp\File\FilesystemException;
2022-02-08 21:42:35 +01:00
use const Amp\Process\IS_WINDOWS;
2015-07-11 03:59:39 +02:00
2022-02-08 19:49:16 +01:00
abstract class FilesystemDriverTest extends FilesystemTest
{
2020-10-08 16:23:44 +02:00
protected File\Filesystem $driver;
2020-06-30 21:45:09 +02:00
2022-02-08 21:42:35 +01:00
public function testListFiles(): void
{
2019-08-23 20:59:26 +02:00
$fixtureDir = Fixture::path();
2020-10-08 16:23:44 +02:00
$actual = $this->driver->listFiles($fixtureDir);
2022-02-08 21:42:35 +01:00
$expected = IS_WINDOWS
2022-02-08 22:04:15 +01:00
? ["dir", "dirlink", "file", "filelink"]
2022-02-08 21:42:35 +01:00
: ["dir", "dirlink", "fifo", "fifolink", "file", "filelink", "linkloop"];
2019-08-23 20:59:26 +02:00
$this->assertSame($expected, $actual);
2015-07-11 03:59:39 +02:00
}
2022-02-08 21:42:35 +01:00
public function testListFilesThrowsIfPathNotADirectory(): void
{
2019-08-23 20:23:33 +02:00
$this->expectException(FilesystemException::class);
2020-10-08 16:23:44 +02:00
$this->driver->listFiles(__FILE__);
2015-08-08 16:09:07 +02:00
}
2022-02-08 21:42:35 +01:00
public function testListFilesThrowsIfPathDoesntExist(): void
{
2019-08-23 20:23:33 +02:00
$this->expectException(FilesystemException::class);
2019-08-23 20:59:26 +02:00
$path = Fixture::path() . "/nonexistent";
2020-10-08 16:23:44 +02:00
$this->driver->listFiles($path);
2015-08-08 16:09:07 +02:00
}
2022-02-08 21:42:35 +01:00
public function testCreateSymlink(): void
{
2019-08-23 20:59:26 +02:00
$fixtureDir = Fixture::path();
2015-07-11 03:59:39 +02:00
$original = "{$fixtureDir}/file";
2019-08-23 20:59:26 +02:00
$link = "{$fixtureDir}/symlink.txt";
2021-10-16 04:53:50 +02:00
$this->driver->createSymlink($original, $link);
2019-08-23 20:59:26 +02:00
$this->assertTrue(\is_link($link));
2020-10-08 16:23:44 +02:00
$this->driver->deleteFile($link);
2015-07-11 03:59:39 +02:00
}
2022-02-08 21:42:35 +01:00
public function testCreateSymlinkFailWhenLinkExists(): void
{
$this->expectException(FilesystemException::class);
$fixtureDir = Fixture::path();
$path = "{$fixtureDir}/file";
2020-10-08 16:23:44 +02:00
$this->driver->createSymlink($path, $path);
}
2022-02-08 21:42:35 +01:00
public function testCreateHardlink(): void
{
$fixtureDir = Fixture::path();
$original = "{$fixtureDir}/file";
$link = "{$fixtureDir}/hardlink.txt";
2021-10-16 04:53:50 +02:00
$this->driver->createHardlink($original, $link);
$this->assertFileExists($link);
$this->assertFalse(\is_link($link));
2020-10-08 16:23:44 +02:00
$this->driver->deleteFile($link);
}
2022-02-08 21:42:35 +01:00
public function testCreateHardlinkFailWhenLinkExists(): void
{
$this->expectException(FilesystemException::class);
$fixtureDir = Fixture::path();
$path = "{$fixtureDir}/file";
2020-10-08 16:23:44 +02:00
$this->driver->createHardlink($path, $path);
}
2022-02-08 21:42:35 +01:00
public function testResolveSymlink(): void
{
2019-08-23 20:59:26 +02:00
$fixtureDir = Fixture::path();
$original = "{$fixtureDir}/file";
2019-08-23 20:59:26 +02:00
$link = "{$fixtureDir}/symlink.txt";
\symlink($original, $link);
2022-02-08 22:04:15 +01:00
$this->assertSame(\str_replace('/', \DIRECTORY_SEPARATOR, $original), $this->driver->resolveSymlink($link));
}
2020-06-24 22:00:24 +02:00
public function symlinkPathProvider(): array
{
return [
2020-06-24 22:00:24 +02:00
'nonExistingPath' => [
static function () {
return Fixture::path() . '/' . \uniqid('amphp-test-', true);
},
],
'notLink' => [
static function () {
return Fixture::path();
},
],
];
}
/**
2020-06-24 22:00:24 +02:00
* @dataProvider symlinkPathProvider
*
*/
2022-02-08 22:04:15 +01:00
public function testResolveSymlinkError(\Closure $linkResolver): void
{
2019-08-23 20:59:26 +02:00
$link = $linkResolver();
2022-02-08 23:43:31 +01:00
$this->expectException(FilesystemException::class);
$result = $this->driver->resolveSymlink($link);
if (IS_WINDOWS) {
self::assertNotSame($result, $link);
$this->markTestSkipped('Build directory itself contains a symlink');
2022-02-08 22:38:50 +01:00
}
}
2022-02-08 21:42:35 +01:00
public function testLinkStatus(): void
{
2019-08-23 20:59:26 +02:00
$fixtureDir = Fixture::path();
2015-07-11 03:59:39 +02:00
$target = "{$fixtureDir}/file";
2019-08-23 20:59:26 +02:00
$link = "{$fixtureDir}/symlink.txt";
2020-10-08 16:23:44 +02:00
$this->driver->createSymlink($target, $link);
$this->assertIsArray($this->driver->getLinkStatus($link));
$this->driver->deleteFile($link);
2015-07-11 03:59:39 +02:00
}
2022-02-08 21:42:35 +01:00
public function testStatus(): void
{
2019-08-23 20:59:26 +02:00
$fixtureDir = Fixture::path();
$path = "{$fixtureDir}/file";
2020-10-08 16:23:44 +02:00
$stat = $this->driver->getStatus($path);
2019-08-23 20:59:26 +02:00
$this->assertIsArray($stat);
2020-06-24 22:00:24 +02:00
$this->assertSameStatus(\stat($path), $stat);
2015-08-08 16:09:07 +02:00
}
2015-07-11 03:59:39 +02:00
2022-02-08 21:42:35 +01:00
public function testDirectoryStatus(): void
{
2019-08-23 20:59:26 +02:00
$fixtureDir = Fixture::path();
2020-10-08 16:23:44 +02:00
$stat = $this->driver->getStatus("{$fixtureDir}/dir");
2019-08-23 20:59:26 +02:00
$this->assertIsArray($stat);
2020-06-24 22:00:24 +02:00
$this->assertSameStatus(\stat("{$fixtureDir}/dir"), $stat);
2015-07-19 15:24:52 +02:00
}
2022-02-08 21:42:35 +01:00
public function testNonexistentPathStatusResolvesToNull(): void
{
2019-08-23 20:59:26 +02:00
$fixtureDir = Fixture::path();
2020-10-08 16:23:44 +02:00
$stat = $this->driver->getStatus("{$fixtureDir}/nonexistent");
2019-08-23 20:59:26 +02:00
$this->assertNull($stat);
2015-08-08 16:09:07 +02:00
}
2015-07-11 03:59:39 +02:00
2022-02-08 21:42:35 +01:00
public function testExists(): void
{
2019-08-23 20:59:26 +02:00
$fixtureDir = Fixture::path();
2020-10-08 16:23:44 +02:00
$this->assertFalse($this->driver->exists("{$fixtureDir}/nonexistent"));
$this->assertTrue($this->driver->exists("{$fixtureDir}/file"));
2015-07-19 15:24:52 +02:00
}
2022-02-08 21:42:35 +01:00
public function testRead(): void
{
2019-08-23 20:59:26 +02:00
$fixtureDir = Fixture::path();
2020-10-08 16:23:44 +02:00
$this->assertSame("small", $this->driver->read("{$fixtureDir}/file"));
2017-06-17 15:36:51 +02:00
}
2022-02-08 21:42:35 +01:00
public function testSize(): void
{
2019-08-23 20:59:26 +02:00
$fixtureDir = Fixture::path();
$path = "{$fixtureDir}/file";
2020-10-08 16:23:44 +02:00
$stat = ($this->driver->getStatus($path));
2019-08-23 20:59:26 +02:00
$size = $stat["size"];
2020-10-08 16:23:44 +02:00
$this->assertSame($size, $this->driver->getSize($path));
2015-08-08 16:09:07 +02:00
}
2015-07-11 03:59:39 +02:00
2022-02-08 21:42:35 +01:00
public function testSizeFailsOnNonexistentPath(): void
{
2019-08-23 20:23:33 +02:00
$this->expectException(FilesystemException::class);
2019-08-23 20:59:26 +02:00
$fixtureDir = Fixture::path();
$path = "{$fixtureDir}/nonexistent";
2020-10-08 16:23:44 +02:00
$this->driver->getSize($path);
2015-08-08 16:09:07 +02:00
}
2022-02-08 21:42:35 +01:00
public function testSizeFailsOnDirectoryPath(): void
{
2019-08-23 20:23:33 +02:00
$this->expectException(FilesystemException::class);
2019-08-23 20:59:26 +02:00
$fixtureDir = Fixture::path();
$path = "{$fixtureDir}/dir";
2020-10-08 16:23:44 +02:00
$this->assertTrue($this->driver->isDirectory($path));
$this->driver->getSize($path);
2015-08-08 16:09:07 +02:00
}
/**
2020-06-24 22:00:24 +02:00
* @dataProvider dataForDirectoryCheck
*/
2022-02-08 21:42:35 +01:00
public function testIsDirectory(bool $expectedResult, string $name): void
{
2019-08-23 20:59:26 +02:00
$fixtureDir = Fixture::path();
$path = "{$fixtureDir}/{$name}";
2020-10-08 16:23:44 +02:00
$this->assertSame($expectedResult, $this->driver->isDirectory($path));
2015-08-08 16:09:07 +02:00
}
2020-06-24 22:00:24 +02:00
public function dataForDirectoryCheck(): \Generator
{
yield 'file' => [false, 'file'];
yield 'filelink' => [false, 'filelink'];
yield 'dir' => [true, 'dir'];
yield 'dirlink' => [true, 'dirlink'];
if (\extension_loaded('posix')) {
yield 'fifo' => [false, 'fifo'];
yield 'fifolink' => [false, 'fifolink'];
}
2022-02-08 21:42:35 +01:00
if (!IS_WINDOWS) {
yield 'linkloop' => [false, 'linkloop'];
}
yield 'nonexistent' => [false, 'nonexistent'];
2015-08-08 16:09:07 +02:00
}
/**
2020-06-24 22:00:24 +02:00
* @dataProvider dataForFileCheck
*/
2022-02-08 21:42:35 +01:00
public function testIsFile(bool $expectedResult, string $name): void
{
2019-08-23 20:59:26 +02:00
$fixtureDir = Fixture::path();
$path = "{$fixtureDir}/{$name}";
2020-10-08 16:23:44 +02:00
$this->assertSame($expectedResult, $this->driver->isFile($path));
2015-08-08 16:09:07 +02:00
}
2020-06-24 22:00:24 +02:00
public function dataForFileCheck(): \Generator
{
yield 'file' => [true, 'file'];
yield 'filelink' => [true, 'filelink'];
yield 'dir' => [false, 'dir'];
yield 'dirlink' => [false, 'dirlink'];
if (\extension_loaded('posix')) {
yield 'fifo' => [false, 'fifo'];
yield 'fifolink' => [false, 'fifolink'];
}
2022-02-08 21:42:35 +01:00
if (!IS_WINDOWS) {
yield 'linkloop' => [false, 'linkloop'];
}
yield 'nonexistent' => [false, 'nonexistent'];
2015-08-08 16:09:07 +02:00
}
/**
2020-06-24 22:00:24 +02:00
* @dataProvider dataForSymlinkCheck
*/
2022-02-08 21:42:35 +01:00
public function testIsSymlink(bool $expectedResult, string $name): void
{
2019-08-23 20:59:26 +02:00
$fixtureDir = Fixture::path();
$path = "{$fixtureDir}/{$name}";
2020-10-08 16:23:44 +02:00
$this->assertSame($expectedResult, $this->driver->isSymlink($path));
2015-08-08 16:09:07 +02:00
}
2020-06-24 22:00:24 +02:00
public function dataForSymlinkCheck(): \Generator
{
yield 'file' => [false, 'file'];
yield 'filelink' => [true, 'filelink'];
yield 'dir' => [false, 'dir'];
yield 'dirlink' => [true, 'dirlink'];
if (\extension_loaded('posix')) {
yield 'fifo' => [false, 'fifo'];
yield 'fifolink' => [true, 'fifolink'];
}
2022-02-08 21:42:35 +01:00
if (!IS_WINDOWS) {
yield 'linkloop' => [true, 'linkloop'];
}
yield 'nonexistent' => [false, 'nonexistent'];
2015-07-11 03:59:39 +02:00
}
2022-02-08 21:42:35 +01:00
public function testMove(): void
{
2019-08-23 20:59:26 +02:00
$fixtureDir = Fixture::path();
2015-07-11 03:59:39 +02:00
2019-08-23 20:59:26 +02:00
$contents1 = "rename test";
$old = "{$fixtureDir}/rename1.txt";
$new = "{$fixtureDir}/rename2.txt";
2015-07-11 03:59:39 +02:00
2020-10-08 16:23:44 +02:00
$this->driver->write($old, $contents1);
2021-10-16 04:53:50 +02:00
$this->driver->move($old, $new);
2020-10-08 16:23:44 +02:00
$contents2 = $this->driver->read($new);
$this->driver->deleteFile($new);
2015-07-11 03:59:39 +02:00
2019-08-23 20:59:26 +02:00
$this->assertSame($contents1, $contents2);
2015-07-11 03:59:39 +02:00
}
2022-02-08 21:42:35 +01:00
public function testMoveFailsOnNonexistentPath(): void
{
$fixtureDir = Fixture::path();
$path = "{$fixtureDir}/nonexistent";
$this->expectException(FilesystemException::class);
2020-10-08 16:23:44 +02:00
$this->driver->move($path, $path);
}
2022-02-08 21:42:35 +01:00
public function testDeleteFile(): void
{
2019-08-23 20:59:26 +02:00
$fixtureDir = Fixture::path();
$toUnlink = "{$fixtureDir}/unlink";
2020-10-08 16:23:44 +02:00
$this->driver->getStatus($toUnlink);
$this->driver->write($toUnlink, "unlink me");
2021-10-16 04:53:50 +02:00
$this->driver->deleteFile($toUnlink);
2020-10-08 16:23:44 +02:00
$this->assertNull($this->driver->getStatus($toUnlink));
2015-07-11 03:59:39 +02:00
}
2022-02-08 21:42:35 +01:00
public function testDeleteFileFailsOnNonexistentPath(): void
{
$fixtureDir = Fixture::path();
$path = "{$fixtureDir}/nonexistent";
$this->expectException(FilesystemException::class);
2020-10-08 16:23:44 +02:00
$this->driver->deleteFile($path);
}
2022-02-08 21:42:35 +01:00
public function testDeleteFileFailsOnDirectory(): void
{
$fixtureDir = Fixture::path();
$dir = "{$fixtureDir}/newdir";
2020-10-08 16:23:44 +02:00
$this->driver->createDirectory($dir);
$this->expectException(FilesystemException::class);
2020-10-08 16:23:44 +02:00
$this->driver->deleteFile($dir);
}
2022-02-08 21:42:35 +01:00
public function testCreateAndDeleteDirectory(): void
{
2019-08-23 20:59:26 +02:00
$fixtureDir = Fixture::path();
2015-07-11 03:59:39 +02:00
2019-08-23 20:59:26 +02:00
$dir = "{$fixtureDir}/newdir";
2015-07-11 03:59:39 +02:00
2019-08-23 20:59:26 +02:00
\umask(0022);
2018-03-15 18:35:10 +01:00
2021-10-16 04:53:50 +02:00
$this->driver->createDirectory($dir);
2020-10-08 16:23:44 +02:00
$stat = $this->driver->getStatus($dir);
2022-02-08 22:38:50 +01:00
if (IS_WINDOWS) {
$this->assertSame('0777', $this->getPermissionsFromStatus($stat));
} else {
$this->assertSame('0755', $this->getPermissionsFromStatus($stat));
}
2021-10-16 04:53:50 +02:00
$this->driver->deleteDirectory($dir);
2020-10-08 16:23:44 +02:00
$this->assertNull($this->driver->getStatus($dir));
2016-09-28 12:39:24 +02:00
2019-08-23 20:59:26 +02:00
// test for 0, because previous array_filter made that not work
$dir = "{$fixtureDir}/newdir/with/recursive/creation/0/1/2";
2016-09-28 12:39:24 +02:00
2021-10-16 04:53:50 +02:00
$this->driver->createDirectoryRecursively($dir, 0764);
2020-10-08 16:23:44 +02:00
$stat = $this->driver->getStatus($dir);
2022-02-08 22:43:53 +01:00
if (IS_WINDOWS) {
$this->assertSame('0777', $this->getPermissionsFromStatus($stat));
} else {
$this->assertSame('0744', $this->getPermissionsFromStatus($stat));
}
2015-08-08 16:09:07 +02:00
}
public function testCreateDirectorySlashEnd(): void
{
$fixtureDir = Fixture::path();
$dir = "{$fixtureDir}/newdir-with-trailing-slash/";
$this->driver->createDirectory($dir, 0764);
$this->assertTrue($this->driver->exists($dir));
}
public function testCreateDirectoryRecursivelySlashEnd(): void
{
$fixtureDir = Fixture::path();
$dir = "{$fixtureDir}/newdir/with/recursive/creation/321/";
$this->driver->createDirectoryRecursively($dir, 0764);
$this->assertTrue($this->driver->exists($dir));
}
2022-02-08 21:42:35 +01:00
public function testCreateDirectoryFailsOnNonexistentPath(): void
{
$fixtureDir = Fixture::path();
$path = "{$fixtureDir}/nonexistent/nonexistent";
$this->expectException(FilesystemException::class);
2020-10-08 16:23:44 +02:00
$this->driver->createDirectory($path);
}
2022-02-08 21:42:35 +01:00
public function testDeleteDirectoryFailsOnNonexistentPath(): void
{
$fixtureDir = Fixture::path();
$path = "{$fixtureDir}/nonexistent";
$this->expectException(FilesystemException::class);
2020-10-08 16:23:44 +02:00
$this->driver->deleteDirectory($path);
}
2022-02-08 21:42:35 +01:00
public function testDeleteDirectoryFailsOnFile(): void
{
$fixtureDir = Fixture::path();
$path = "{$fixtureDir}/file";
$this->expectException(FilesystemException::class);
2020-10-08 16:23:44 +02:00
$this->driver->deleteDirectory($path);
}
2022-02-08 21:42:35 +01:00
public function testMtime(): void
{
2019-08-23 20:59:26 +02:00
$fixtureDir = Fixture::path();
$path = "{$fixtureDir}/file";
2020-10-08 16:23:44 +02:00
$stat = $this->driver->getStatus($path);
2019-08-23 20:59:26 +02:00
$statMtime = $stat["mtime"];
2020-10-08 16:23:44 +02:00
$this->assertSame($statMtime, $this->driver->getModificationTime($path));
2015-08-08 16:09:07 +02:00
}
2022-02-08 21:42:35 +01:00
public function testMtimeFailsOnNonexistentPath(): void
{
2019-08-23 20:59:26 +02:00
$fixtureDir = Fixture::path();
$path = "{$fixtureDir}/nonexistent";
$this->expectException(FilesystemException::class);
2020-10-08 16:23:44 +02:00
$this->driver->getModificationTime($path);
2015-08-08 16:09:07 +02:00
}
2022-02-08 21:42:35 +01:00
public function testAtime(): void
{
2019-08-23 20:59:26 +02:00
$fixtureDir = Fixture::path();
$path = "{$fixtureDir}/file";
2020-10-08 16:23:44 +02:00
$stat = $this->driver->getStatus($path);
2019-08-23 20:59:26 +02:00
$statAtime = $stat["atime"];
2020-10-08 16:23:44 +02:00
$this->assertSame($statAtime, $this->driver->getAccessTime($path));
2015-08-08 16:09:07 +02:00
}
2022-02-08 21:42:35 +01:00
public function testAtimeFailsOnNonexistentPath(): void
{
2019-08-23 20:59:26 +02:00
$fixtureDir = Fixture::path();
$path = "{$fixtureDir}/nonexistent";
$this->expectException(FilesystemException::class);
2020-10-08 16:23:44 +02:00
$this->driver->getAccessTime($path);
2015-08-08 16:09:07 +02:00
}
2022-02-08 21:42:35 +01:00
public function testCtime(): void
{
2019-08-23 20:59:26 +02:00
$fixtureDir = Fixture::path();
$path = "{$fixtureDir}/file";
2020-10-08 16:23:44 +02:00
$stat = $this->driver->getStatus($path);
2019-08-23 20:59:26 +02:00
$statCtime = $stat["ctime"];
2020-10-08 16:23:44 +02:00
$this->assertSame($statCtime, $this->driver->getCreationTime($path));
2015-08-08 16:09:07 +02:00
}
2022-02-08 21:42:35 +01:00
public function testCtimeFailsOnNonexistentPath(): void
{
2019-08-23 20:59:26 +02:00
$fixtureDir = Fixture::path();
$path = "{$fixtureDir}/nonexistent";
$this->expectException(FilesystemException::class);
2020-10-08 16:23:44 +02:00
$this->driver->getCreationTime($path);
2015-07-11 03:59:39 +02:00
}
2015-07-18 20:53:46 +02:00
/**
* @group slow
*/
2022-02-08 21:42:35 +01:00
public function testTouch(): void
{
2019-08-23 20:59:26 +02:00
$fixtureDir = Fixture::path();
2015-07-18 20:53:46 +02:00
2019-08-23 20:59:26 +02:00
$touch = "{$fixtureDir}/touch";
2020-10-08 16:23:44 +02:00
$this->driver->write($touch, "touch me");
2015-07-18 20:53:46 +02:00
2020-10-08 16:23:44 +02:00
$oldStat = $this->driver->getStatus($touch);
2021-10-16 04:53:50 +02:00
$this->driver->touch($touch, \time() + 10, \time() + 20);
2020-10-08 16:23:44 +02:00
$newStat = $this->driver->getStatus($touch);
$this->driver->deleteFile($touch);
2015-07-18 20:53:46 +02:00
2019-08-23 20:59:26 +02:00
$this->assertTrue($newStat["atime"] > $oldStat["atime"]);
$this->assertTrue($newStat["mtime"] > $oldStat["mtime"]);
2015-07-18 20:53:46 +02:00
}
2018-03-15 18:35:10 +01:00
2022-02-08 21:42:35 +01:00
public function testTouchFailsOnNonexistentPath(): void
{
$fixtureDir = Fixture::path();
$path = "{$fixtureDir}/nonexistent/nonexistent";
$this->expectException(FilesystemException::class);
2020-10-08 16:23:44 +02:00
$this->driver->touch($path);
}
2022-02-08 21:42:35 +01:00
public function testChangePermissions(): void
{
$fixtureDir = Fixture::path();
$path = "{$fixtureDir}/file";
2020-10-08 16:23:44 +02:00
$stat = $this->driver->getStatus($path);
$this->assertNotSame('0777', \substr(\decoct($stat['mode']), -4));
2021-10-16 04:53:50 +02:00
$this->driver->changePermissions($path, 0777);
2020-10-08 16:23:44 +02:00
$stat = $this->driver->getStatus($path);
2022-02-08 22:38:50 +01:00
if (IS_WINDOWS) {
$this->assertSame('0666', \substr(\decoct($stat['mode']), -4));
} else {
$this->assertSame('0777', \substr(\decoct($stat['mode']), -4));
}
}
2022-02-08 21:42:35 +01:00
public function testChangePermissionsFailsOnNonexistentPath(): void
{
$fixtureDir = Fixture::path();
$path = "{$fixtureDir}/nonexistent";
$this->expectException(FilesystemException::class);
2020-10-08 16:23:44 +02:00
$this->driver->changePermissions($path, 0777);
}
2022-02-08 21:42:35 +01:00
public function testChangeOwner(): void
{
2022-02-08 22:04:15 +01:00
if (IS_WINDOWS) {
$this->markTestSkipped('Not supported on Windows');
}
$fixtureDir = Fixture::path();
$path = "{$fixtureDir}/file";
2020-10-08 16:23:44 +02:00
$this->driver->getStatus($path);
$user = \fileowner($path);
2022-02-08 22:04:15 +01:00
$this->driver->changeOwner($path, $user);
2021-10-16 04:53:50 +02:00
self::assertSame($user, \fileowner($path));
}
2022-02-08 21:42:35 +01:00
public function testChangeOwnerFailsOnNonexistentPath(): void
{
2022-02-08 22:04:15 +01:00
if (IS_WINDOWS) {
$this->markTestSkipped('Not supported on Windows');
}
$fixtureDir = Fixture::path();
$path = "{$fixtureDir}/nonexistent";
$this->expectException(FilesystemException::class);
2022-02-08 22:04:15 +01:00
$this->driver->changeOwner($path, 0);
}
2020-06-24 22:00:24 +02:00
2020-06-30 21:45:09 +02:00
protected function setUp(): void
{
parent::setUp();
$this->driver = new File\Filesystem($this->createDriver());
}
2022-02-08 19:49:16 +01:00
abstract protected function createDriver(): File\FilesystemDriver;
2020-06-30 21:45:09 +02:00
2020-06-24 22:00:24 +02:00
private function assertSameStatus(array $expected, array $actual): void
{
$filter = function (array $stat) {
$filtered = \array_filter(
$stat,
function (string $key): bool {
return !\is_numeric($key);
},
ARRAY_FILTER_USE_KEY
);
\ksort($filtered);
return $filtered;
};
$this->assertSame($filter($expected), $filter($actual));
}
private function getPermissionsFromStatus(array $stat): string
{
return \substr(\decoct($stat["mode"]), 1);
}
2015-07-11 03:59:39 +02:00
}