2016-12-30 03:59:59 +01:00
|
|
|
<?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
|
|
|
|
2019-08-23 20:00:26 +02:00
|
|
|
use Amp\File;
|
2019-08-23 20:23:33 +02:00
|
|
|
use Amp\File\FilesystemException;
|
2015-07-11 03:59:39 +02:00
|
|
|
|
2019-08-23 20:59:26 +02:00
|
|
|
abstract class DriverTest extends FilesystemTest
|
2018-10-27 17:57:31 +02:00
|
|
|
{
|
2020-10-08 16:23:44 +02:00
|
|
|
protected File\Filesystem $driver;
|
2020-06-30 21:45:09 +02:00
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
public function testListFiles()
|
2018-10-27 17:57:31 +02:00
|
|
|
{
|
2019-08-23 20:59:26 +02:00
|
|
|
$fixtureDir = Fixture::path();
|
2020-10-08 16:23:44 +02:00
|
|
|
$actual = $this->driver->listFiles($fixtureDir);
|
2020-06-23 22:40:48 +02:00
|
|
|
$expected = ["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
|
|
|
}
|
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
public function testListFilesThrowsIfPathNotADirectory()
|
2018-10-27 17:57:31 +02:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
public function testListFilesThrowsIfPathDoesntExist()
|
2018-10-27 17:57:31 +02:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
public function testCreateSymlink()
|
2018-10-27 17:57:31 +02:00
|
|
|
{
|
2019-08-23 20:59:26 +02:00
|
|
|
$fixtureDir = Fixture::path();
|
2015-07-11 03:59:39 +02:00
|
|
|
|
2020-06-23 22:40:48 +02:00
|
|
|
$original = "{$fixtureDir}/file";
|
2019-08-23 20:59:26 +02:00
|
|
|
$link = "{$fixtureDir}/symlink.txt";
|
2020-10-08 16:23:44 +02:00
|
|
|
$this->assertNull($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
|
|
|
}
|
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
public function testCreateSymlinkFailWhenLinkExists()
|
2020-06-23 22:40:48 +02:00
|
|
|
{
|
|
|
|
$this->expectException(FilesystemException::class);
|
|
|
|
|
|
|
|
$fixtureDir = Fixture::path();
|
|
|
|
$path = "{$fixtureDir}/file";
|
2020-10-08 16:23:44 +02:00
|
|
|
$this->driver->createSymlink($path, $path);
|
2020-06-23 22:40:48 +02:00
|
|
|
}
|
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
public function testCreateHardlink()
|
2020-06-23 22:40:48 +02:00
|
|
|
{
|
|
|
|
$fixtureDir = Fixture::path();
|
|
|
|
|
|
|
|
$original = "{$fixtureDir}/file";
|
|
|
|
$link = "{$fixtureDir}/hardlink.txt";
|
2020-10-08 16:23:44 +02:00
|
|
|
$this->assertNull($this->driver->createHardlink($original, $link));
|
2020-06-23 22:40:48 +02:00
|
|
|
$this->assertFileExists($link);
|
|
|
|
$this->assertFalse(\is_link($link));
|
2020-10-08 16:23:44 +02:00
|
|
|
$this->driver->deleteFile($link);
|
2020-06-23 22:40:48 +02:00
|
|
|
}
|
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
public function testCreateHardlinkFailWhenLinkExists()
|
2020-06-23 22:40:48 +02:00
|
|
|
{
|
|
|
|
$this->expectException(FilesystemException::class);
|
|
|
|
|
|
|
|
$fixtureDir = Fixture::path();
|
|
|
|
$path = "{$fixtureDir}/file";
|
2020-10-08 16:23:44 +02:00
|
|
|
$this->driver->createHardlink($path, $path);
|
2020-06-23 22:40:48 +02:00
|
|
|
}
|
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
public function testResolveSymlink()
|
2018-10-27 17:57:31 +02:00
|
|
|
{
|
2019-08-23 20:59:26 +02:00
|
|
|
$fixtureDir = Fixture::path();
|
2018-07-16 02:32:59 +02:00
|
|
|
|
2020-06-23 22:40:48 +02:00
|
|
|
$original = "{$fixtureDir}/file";
|
2019-08-23 20:59:26 +02:00
|
|
|
$link = "{$fixtureDir}/symlink.txt";
|
|
|
|
\symlink($original, $link);
|
2018-07-16 02:32:59 +02:00
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
$this->assertSame($original, $this->driver->resolveSymlink($link));
|
2018-07-16 02:32:59 +02:00
|
|
|
}
|
|
|
|
|
2020-06-24 22:00:24 +02:00
|
|
|
public function symlinkPathProvider(): array
|
2018-10-27 17:57:31 +02:00
|
|
|
{
|
2018-07-16 02:32:59 +02:00
|
|
|
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();
|
|
|
|
},
|
|
|
|
],
|
2018-07-16 02:32:59 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-06-24 22:00:24 +02:00
|
|
|
* @dataProvider symlinkPathProvider
|
2018-07-16 02:32:59 +02:00
|
|
|
*
|
|
|
|
* @param \Closure $linkResolver
|
2020-06-30 21:45:09 +02:00
|
|
|
*
|
2020-06-24 22:00:24 +02:00
|
|
|
* @return \Generator
|
2018-07-16 02:32:59 +02:00
|
|
|
*/
|
2020-10-08 16:23:44 +02:00
|
|
|
public function testResolveSymlinkError(\Closure $linkResolver)
|
2018-10-27 17:57:31 +02:00
|
|
|
{
|
2019-08-23 20:23:33 +02:00
|
|
|
$this->expectException(FilesystemException::class);
|
|
|
|
|
2019-08-23 20:59:26 +02:00
|
|
|
$link = $linkResolver();
|
2018-07-16 02:32:59 +02:00
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
$this->driver->resolveSymlink($link);
|
2018-07-16 02:32:59 +02:00
|
|
|
}
|
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
public function testLinkStatus()
|
2018-10-27 17:57:31 +02:00
|
|
|
{
|
2019-08-23 20:59:26 +02:00
|
|
|
$fixtureDir = Fixture::path();
|
2015-07-11 03:59:39 +02:00
|
|
|
|
2020-06-23 22:40:48 +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
|
|
|
}
|
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
public function testStatus()
|
2018-10-27 17:57:31 +02:00
|
|
|
{
|
2019-08-23 20:59:26 +02:00
|
|
|
$fixtureDir = Fixture::path();
|
2020-06-23 22:40:48 +02:00
|
|
|
$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
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
public function testDirectoryStatus()
|
2018-10-27 17:57:31 +02:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
public function testNonexistentPathStatusResolvesToNull()
|
2018-10-27 17:57:31 +02:00
|
|
|
{
|
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
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
public function testExists()
|
2018-10-27 17:57:31 +02:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
public function testRead()
|
2018-10-27 17:57:31 +02:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
public function testSize()
|
2018-10-27 17:57:31 +02:00
|
|
|
{
|
2019-08-23 20:59:26 +02:00
|
|
|
$fixtureDir = Fixture::path();
|
2020-06-23 22:40:48 +02:00
|
|
|
$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
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
public function testSizeFailsOnNonexistentPath()
|
2018-10-27 17:57:31 +02:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
public function testSizeFailsOnDirectoryPath()
|
2018-10-27 17:57:31 +02:00
|
|
|
{
|
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-23 22:40:48 +02:00
|
|
|
/**
|
2020-06-24 22:00:24 +02:00
|
|
|
* @dataProvider dataForDirectoryCheck
|
2020-06-23 22:40:48 +02:00
|
|
|
*/
|
2020-10-08 16:23:44 +02:00
|
|
|
public function testIsDirectory(bool $expectedResult, string $name)
|
2018-10-27 17:57:31 +02:00
|
|
|
{
|
2019-08-23 20:59:26 +02:00
|
|
|
$fixtureDir = Fixture::path();
|
2020-06-23 22:40:48 +02:00
|
|
|
$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
|
2018-10-27 17:57:31 +02:00
|
|
|
{
|
2020-06-23 22:40:48 +02:00
|
|
|
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'];
|
|
|
|
}
|
|
|
|
yield 'linkloop' => [false, 'linkloop'];
|
|
|
|
yield 'nonexistent' => [false, 'nonexistent'];
|
2015-08-08 16:09:07 +02:00
|
|
|
}
|
|
|
|
|
2020-06-23 22:40:48 +02:00
|
|
|
/**
|
2020-06-24 22:00:24 +02:00
|
|
|
* @dataProvider dataForFileCheck
|
2020-06-23 22:40:48 +02:00
|
|
|
*/
|
2020-10-08 16:23:44 +02:00
|
|
|
public function testIsFile(bool $expectedResult, string $name)
|
2018-10-27 17:57:31 +02:00
|
|
|
{
|
2019-08-23 20:59:26 +02:00
|
|
|
$fixtureDir = Fixture::path();
|
2020-06-23 22:40:48 +02:00
|
|
|
$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
|
2018-10-27 17:57:31 +02:00
|
|
|
{
|
2020-06-23 22:40:48 +02:00
|
|
|
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'];
|
|
|
|
}
|
|
|
|
yield 'linkloop' => [false, 'linkloop'];
|
|
|
|
yield 'nonexistent' => [false, 'nonexistent'];
|
2015-08-08 16:09:07 +02:00
|
|
|
}
|
|
|
|
|
2020-06-23 22:40:48 +02:00
|
|
|
/**
|
2020-06-24 22:00:24 +02:00
|
|
|
* @dataProvider dataForSymlinkCheck
|
2020-06-23 22:40:48 +02:00
|
|
|
*/
|
2020-10-08 16:23:44 +02:00
|
|
|
public function testIsSymlink(bool $expectedResult, string $name)
|
2018-10-27 17:57:31 +02:00
|
|
|
{
|
2019-08-23 20:59:26 +02:00
|
|
|
$fixtureDir = Fixture::path();
|
2020-06-23 22:40:48 +02:00
|
|
|
$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
|
2018-10-27 17:57:31 +02:00
|
|
|
{
|
2020-06-23 22:40:48 +02:00
|
|
|
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'];
|
|
|
|
}
|
|
|
|
yield 'linkloop' => [true, 'linkloop'];
|
|
|
|
yield 'nonexistent' => [false, 'nonexistent'];
|
2015-07-11 03:59:39 +02:00
|
|
|
}
|
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
public function testMove()
|
2018-10-27 17:57:31 +02:00
|
|
|
{
|
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);
|
|
|
|
$this->assertNull($this->driver->move($old, $new));
|
|
|
|
$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
|
|
|
}
|
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
public function testMoveFailsOnNonexistentPath()
|
2020-06-23 22:40:48 +02:00
|
|
|
{
|
|
|
|
$fixtureDir = Fixture::path();
|
|
|
|
$path = "{$fixtureDir}/nonexistent";
|
|
|
|
|
|
|
|
$this->expectException(FilesystemException::class);
|
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
$this->driver->move($path, $path);
|
2020-06-23 22:40:48 +02:00
|
|
|
}
|
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
public function testDeleteFile()
|
2018-10-27 17:57:31 +02:00
|
|
|
{
|
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");
|
|
|
|
$this->assertNull($this->driver->deleteFile($toUnlink));
|
|
|
|
$this->assertNull($this->driver->getStatus($toUnlink));
|
2015-07-11 03:59:39 +02:00
|
|
|
}
|
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
public function testDeleteFileFailsOnNonexistentPath()
|
2020-06-23 22:40:48 +02:00
|
|
|
{
|
|
|
|
$fixtureDir = Fixture::path();
|
|
|
|
$path = "{$fixtureDir}/nonexistent";
|
|
|
|
|
|
|
|
$this->expectException(FilesystemException::class);
|
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
$this->driver->deleteFile($path);
|
2020-06-23 22:40:48 +02:00
|
|
|
}
|
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
public function testDeleteFileFailsOnDirectory()
|
2020-06-23 22:40:48 +02:00
|
|
|
{
|
|
|
|
$fixtureDir = Fixture::path();
|
|
|
|
$dir = "{$fixtureDir}/newdir";
|
2020-10-08 16:23:44 +02:00
|
|
|
$this->driver->createDirectory($dir);
|
2020-06-23 22:40:48 +02:00
|
|
|
|
|
|
|
$this->expectException(FilesystemException::class);
|
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
$this->driver->deleteFile($dir);
|
2020-06-23 22:40:48 +02:00
|
|
|
}
|
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
public function testCreateAndDeleteDirectory()
|
2018-10-27 17:57:31 +02:00
|
|
|
{
|
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
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
$this->assertNull($this->driver->createDirectory($dir));
|
|
|
|
$stat = $this->driver->getStatus($dir);
|
2020-06-24 22:00:24 +02:00
|
|
|
$this->assertSame('0755', $this->getPermissionsFromStatus($stat));
|
2020-10-08 16:23:44 +02:00
|
|
|
$this->assertNull($this->driver->deleteDirectory($dir));
|
|
|
|
$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
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
$this->assertNull($this->driver->createDirectoryRecursively($dir, 0764));
|
|
|
|
$stat = $this->driver->getStatus($dir);
|
2020-06-24 22:00:24 +02:00
|
|
|
$this->assertSame('0744', $this->getPermissionsFromStatus($stat));
|
2015-08-08 16:09:07 +02:00
|
|
|
}
|
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
public function testCreateDirectoryFailsOnNonexistentPath()
|
2020-06-23 22:40:48 +02:00
|
|
|
{
|
|
|
|
$fixtureDir = Fixture::path();
|
|
|
|
$path = "{$fixtureDir}/nonexistent/nonexistent";
|
|
|
|
|
|
|
|
$this->expectException(FilesystemException::class);
|
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
$this->driver->createDirectory($path);
|
2020-06-23 22:40:48 +02:00
|
|
|
}
|
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
public function testDeleteDirectoryFailsOnNonexistentPath()
|
2020-06-23 22:40:48 +02:00
|
|
|
{
|
|
|
|
$fixtureDir = Fixture::path();
|
|
|
|
$path = "{$fixtureDir}/nonexistent";
|
|
|
|
|
|
|
|
$this->expectException(FilesystemException::class);
|
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
$this->driver->deleteDirectory($path);
|
2020-06-23 22:40:48 +02:00
|
|
|
}
|
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
public function testDeleteDirectoryFailsOnFile()
|
2020-06-23 22:40:48 +02:00
|
|
|
{
|
|
|
|
$fixtureDir = Fixture::path();
|
|
|
|
$path = "{$fixtureDir}/file";
|
|
|
|
|
|
|
|
$this->expectException(FilesystemException::class);
|
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
$this->driver->deleteDirectory($path);
|
2020-06-23 22:40:48 +02:00
|
|
|
}
|
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
public function testMtime()
|
2018-10-27 17:57:31 +02:00
|
|
|
{
|
2019-08-23 20:59:26 +02:00
|
|
|
$fixtureDir = Fixture::path();
|
2020-06-23 22:40:48 +02:00
|
|
|
$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
|
|
|
}
|
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
public function testMtimeFailsOnNonexistentPath()
|
2018-10-27 17:57:31 +02:00
|
|
|
{
|
2019-08-23 20:59:26 +02:00
|
|
|
$fixtureDir = Fixture::path();
|
|
|
|
$path = "{$fixtureDir}/nonexistent";
|
2020-06-23 22:40:48 +02:00
|
|
|
|
|
|
|
$this->expectException(FilesystemException::class);
|
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
$this->driver->getModificationTime($path);
|
2015-08-08 16:09:07 +02:00
|
|
|
}
|
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
public function testAtime()
|
2018-10-27 17:57:31 +02:00
|
|
|
{
|
2019-08-23 20:59:26 +02:00
|
|
|
$fixtureDir = Fixture::path();
|
2020-06-23 22:40:48 +02:00
|
|
|
$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
|
|
|
}
|
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
public function testAtimeFailsOnNonexistentPath()
|
2018-10-27 17:57:31 +02:00
|
|
|
{
|
2019-08-23 20:59:26 +02:00
|
|
|
$fixtureDir = Fixture::path();
|
|
|
|
$path = "{$fixtureDir}/nonexistent";
|
2020-06-23 22:40:48 +02:00
|
|
|
|
|
|
|
$this->expectException(FilesystemException::class);
|
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
$this->driver->getAccessTime($path);
|
2015-08-08 16:09:07 +02:00
|
|
|
}
|
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
public function testCtime()
|
2018-10-27 17:57:31 +02:00
|
|
|
{
|
2019-08-23 20:59:26 +02:00
|
|
|
$fixtureDir = Fixture::path();
|
2020-06-23 22:40:48 +02:00
|
|
|
$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
|
|
|
}
|
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
public function testCtimeFailsOnNonexistentPath()
|
2018-10-27 17:57:31 +02:00
|
|
|
{
|
2019-08-23 20:59:26 +02:00
|
|
|
$fixtureDir = Fixture::path();
|
|
|
|
$path = "{$fixtureDir}/nonexistent";
|
2020-06-23 22:40:48 +02:00
|
|
|
|
|
|
|
$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
|
|
|
|
*/
|
2020-10-08 16:23:44 +02:00
|
|
|
public function testTouch()
|
2018-10-27 17:57:31 +02:00
|
|
|
{
|
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);
|
|
|
|
$this->assertNull($this->driver->touch($touch, \time() + 10, \time() + 20));
|
|
|
|
$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
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
public function testTouchFailsOnNonexistentPath()
|
2020-06-23 22:40:48 +02:00
|
|
|
{
|
|
|
|
$fixtureDir = Fixture::path();
|
|
|
|
$path = "{$fixtureDir}/nonexistent/nonexistent";
|
|
|
|
|
|
|
|
$this->expectException(FilesystemException::class);
|
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
$this->driver->touch($path);
|
2020-06-23 22:40:48 +02:00
|
|
|
}
|
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
public function testChangePermissions()
|
2020-06-23 22:40:48 +02:00
|
|
|
{
|
|
|
|
$fixtureDir = Fixture::path();
|
|
|
|
|
|
|
|
$path = "{$fixtureDir}/file";
|
2020-10-08 16:23:44 +02:00
|
|
|
$stat = $this->driver->getStatus($path);
|
2020-06-23 22:40:48 +02:00
|
|
|
$this->assertNotSame('0777', \substr(\decoct($stat['mode']), -4));
|
2020-10-08 16:23:44 +02:00
|
|
|
$this->assertNull($this->driver->changePermissions($path, 0777));
|
|
|
|
$stat = $this->driver->getStatus($path);
|
2020-06-23 22:40:48 +02:00
|
|
|
$this->assertSame('0777', \substr(\decoct($stat['mode']), -4));
|
|
|
|
}
|
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
public function testChangePermissionsFailsOnNonexistentPath()
|
2020-06-23 22:40:48 +02:00
|
|
|
{
|
|
|
|
$fixtureDir = Fixture::path();
|
|
|
|
$path = "{$fixtureDir}/nonexistent";
|
|
|
|
|
|
|
|
$this->expectException(FilesystemException::class);
|
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
$this->driver->changePermissions($path, 0777);
|
2020-06-23 22:40:48 +02:00
|
|
|
}
|
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
public function testChangeOwner()
|
2020-06-23 22:40:48 +02:00
|
|
|
{
|
|
|
|
$fixtureDir = Fixture::path();
|
|
|
|
|
|
|
|
$path = "{$fixtureDir}/file";
|
2020-10-08 16:23:44 +02:00
|
|
|
$this->driver->getStatus($path);
|
2020-06-23 22:40:48 +02:00
|
|
|
$user = \fileowner($path);
|
2020-10-08 16:23:44 +02:00
|
|
|
$this->assertNull($this->driver->changeOwner($path, $user, null));
|
2020-06-23 22:40:48 +02:00
|
|
|
}
|
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
public function testChangeOwnerFailsOnNonexistentPath()
|
2020-06-23 22:40:48 +02:00
|
|
|
{
|
|
|
|
$fixtureDir = Fixture::path();
|
|
|
|
$path = "{$fixtureDir}/nonexistent";
|
|
|
|
|
|
|
|
$this->expectException(FilesystemException::class);
|
|
|
|
|
2020-10-08 16:23:44 +02:00
|
|
|
$this->driver->changeOwner($path, 0, null);
|
2020-06-23 22:40:48 +02:00
|
|
|
}
|
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());
|
|
|
|
}
|
|
|
|
|
|
|
|
abstract protected function createDriver(): File\Driver;
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $stat
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
private function getPermissionsFromStatus(array $stat): string
|
|
|
|
{
|
|
|
|
return \substr(\decoct($stat["mode"]), 1);
|
|
|
|
}
|
2015-07-11 03:59:39 +02:00
|
|
|
}
|