mirror of
https://github.com/danog/file.git
synced 2024-11-30 04:19:39 +01:00
Use Fixture in Driver test; general test cleanup
This commit is contained in:
parent
7e864b9578
commit
477683f58f
@ -3,7 +3,7 @@
|
|||||||
namespace Amp\File\Test;
|
namespace Amp\File\Test;
|
||||||
|
|
||||||
class BlockingDriverTest extends DriverTest {
|
class BlockingDriverTest extends DriverTest {
|
||||||
protected function lRun(callable $cb) {
|
protected function execute(callable $cb) {
|
||||||
\Amp\Loop::run(function() use ($cb) {
|
\Amp\Loop::run(function() use ($cb) {
|
||||||
\Amp\File\filesystem(new \Amp\File\BlockingDriver);
|
\Amp\File\filesystem(new \Amp\File\BlockingDriver);
|
||||||
\Amp\Promise\rethrow(new \Amp\Coroutine($cb()));
|
\Amp\Promise\rethrow(new \Amp\Coroutine($cb()));
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
namespace Amp\File\Test;
|
namespace Amp\File\Test;
|
||||||
|
|
||||||
class BlockingHandleTest extends HandleTest {
|
class BlockingHandleTest extends HandleTest {
|
||||||
protected function lRun(callable $cb) {
|
protected function execute(callable $cb) {
|
||||||
\Amp\Loop::run(function() use ($cb) {
|
\Amp\Loop::run(function() use ($cb) {
|
||||||
\Amp\File\filesystem(new \Amp\File\BlockingDriver);
|
\Amp\File\filesystem(new \Amp\File\BlockingDriver);
|
||||||
\Amp\Promise\rethrow(new \Amp\Coroutine($cb()));
|
\Amp\Promise\rethrow(new \Amp\Coroutine($cb()));
|
||||||
|
@ -6,68 +6,21 @@ use Amp\File as file;
|
|||||||
use Amp\PHPUnit\TestCase;
|
use Amp\PHPUnit\TestCase;
|
||||||
|
|
||||||
abstract class DriverTest extends TestCase {
|
abstract class DriverTest extends TestCase {
|
||||||
private static $fixtureId;
|
|
||||||
private static $umask;
|
|
||||||
|
|
||||||
private static function getFixturePath() {
|
|
||||||
if (empty(self::$fixtureId)) {
|
|
||||||
self::$fixtureId = \uniqid();
|
|
||||||
}
|
|
||||||
|
|
||||||
return \sys_get_temp_dir() . "/amphp_file_fixture/" . __CLASS__ . self::$fixtureId;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static function clearFixtureDir() {
|
|
||||||
$fixtureDir = self::getFixturePath();
|
|
||||||
if (!file_exists($fixtureDir)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (\stripos(\PHP_OS, "win") === 0) {
|
|
||||||
\system('rd /Q /S "' . $fixtureDir . '"');
|
|
||||||
} else {
|
|
||||||
\system('/bin/rm -rf ' . \escapeshellarg($fixtureDir));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function setUpBeforeClass() {
|
|
||||||
$fixtureDir = self::getFixturePath();
|
|
||||||
|
|
||||||
self::clearFixtureDir();
|
|
||||||
self::$umask = umask(0022);
|
|
||||||
|
|
||||||
if (!\mkdir($fixtureDir, $mode = 0777, $recursive = true)) {
|
|
||||||
throw new \RuntimeException(
|
|
||||||
"Failed creating temporary test fixture directory: {$fixtureDir}"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (!\mkdir($fixtureDir . "/dir", $mode = 0777, $recursive = true)) {
|
|
||||||
throw new \RuntimeException(
|
|
||||||
"Failed creating temporary test fixture directory"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (!\file_put_contents($fixtureDir . "/small.txt", "small")) {
|
|
||||||
throw new \RuntimeException(
|
|
||||||
"Failed creating temporary test fixture file"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function tearDownAfterClass() {
|
|
||||||
self::clearFixtureDir();
|
|
||||||
umask(self::$umask);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function setUp() {
|
protected function setUp() {
|
||||||
file\StatCache::clear();
|
Fixture::init();
|
||||||
|
File\StatCache::clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract protected function lRun(callable $cb);
|
protected function tearDown() {
|
||||||
|
Fixture::clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract protected function execute(callable $cb);
|
||||||
|
|
||||||
public function testScandir() {
|
public function testScandir() {
|
||||||
$this->lRun(function () {
|
$this->execute(function () {
|
||||||
$fixtureDir = self::getFixturePath();
|
$fixtureDir = Fixture::path();
|
||||||
$actual = (yield file\scandir($fixtureDir));
|
$actual = (yield File\scandir($fixtureDir));
|
||||||
$expected = ["dir", "small.txt"];
|
$expected = ["dir", "small.txt"];
|
||||||
$this->assertSame($expected, $actual);
|
$this->assertSame($expected, $actual);
|
||||||
});
|
});
|
||||||
@ -77,8 +30,8 @@ abstract class DriverTest extends TestCase {
|
|||||||
* @expectedException \Amp\File\FilesystemException
|
* @expectedException \Amp\File\FilesystemException
|
||||||
*/
|
*/
|
||||||
public function testScandirThrowsIfPathNotADirectory() {
|
public function testScandirThrowsIfPathNotADirectory() {
|
||||||
$this->lRun(function () {
|
$this->execute(function () {
|
||||||
(yield file\scandir(__FILE__));
|
(yield File\scandir(__FILE__));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,76 +39,76 @@ abstract class DriverTest extends TestCase {
|
|||||||
* @expectedException \Amp\File\FilesystemException
|
* @expectedException \Amp\File\FilesystemException
|
||||||
*/
|
*/
|
||||||
public function testScandirThrowsIfPathDoesntExist() {
|
public function testScandirThrowsIfPathDoesntExist() {
|
||||||
$this->lRun(function () {
|
$this->execute(function () {
|
||||||
$path = self::getFixturePath() . "/nonexistent";
|
$path = Fixture::path() . "/nonexistent";
|
||||||
(yield file\scandir($path));
|
(yield File\scandir($path));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSymlink() {
|
public function testSymlink() {
|
||||||
$this->lRun(function () {
|
$this->execute(function () {
|
||||||
$fixtureDir = self::getFixturePath();
|
$fixtureDir = Fixture::path();
|
||||||
|
|
||||||
$original = "{$fixtureDir}/small.txt";
|
$original = "{$fixtureDir}/small.txt";
|
||||||
$link = "{$fixtureDir}/symlink.txt";
|
$link = "{$fixtureDir}/symlink.txt";
|
||||||
$this->assertTrue(yield file\symlink($original, $link));
|
$this->assertTrue(yield File\symlink($original, $link));
|
||||||
$this->assertTrue(\is_link($link));
|
$this->assertTrue(\is_link($link));
|
||||||
yield file\unlink($link);
|
yield File\unlink($link);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testLstat() {
|
public function testLstat() {
|
||||||
$this->lRun(function () {
|
$this->execute(function () {
|
||||||
$fixtureDir = self::getFixturePath();
|
$fixtureDir = Fixture::path();
|
||||||
|
|
||||||
$target = "{$fixtureDir}/small.txt";
|
$target = "{$fixtureDir}/small.txt";
|
||||||
$link = "{$fixtureDir}/symlink.txt";
|
$link = "{$fixtureDir}/symlink.txt";
|
||||||
$this->assertTrue(yield file\symlink($target, $link));
|
$this->assertTrue(yield File\symlink($target, $link));
|
||||||
$this->assertTrue(is_array(yield file\lstat($link)));
|
$this->assertTrue(is_array(yield File\lstat($link)));
|
||||||
yield file\unlink($link);
|
yield File\unlink($link);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFileStat() {
|
public function testFileStat() {
|
||||||
$this->lRun(function () {
|
$this->execute(function () {
|
||||||
$fixtureDir = self::getFixturePath();
|
$fixtureDir = Fixture::path();
|
||||||
$stat = (yield file\stat("{$fixtureDir}/small.txt"));
|
$stat = (yield File\stat("{$fixtureDir}/small.txt"));
|
||||||
$this->assertInternalType("array", $stat);
|
$this->assertInternalType("array", $stat);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDirStat() {
|
public function testDirStat() {
|
||||||
$this->lRun(function () {
|
$this->execute(function () {
|
||||||
$fixtureDir = self::getFixturePath();
|
$fixtureDir = Fixture::path();
|
||||||
$stat = (yield file\stat("{$fixtureDir}/dir"));
|
$stat = (yield File\stat("{$fixtureDir}/dir"));
|
||||||
$this->assertInternalType("array", $stat);
|
$this->assertInternalType("array", $stat);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNonexistentPathStatResolvesToNull() {
|
public function testNonexistentPathStatResolvesToNull() {
|
||||||
$this->lRun(function () {
|
$this->execute(function () {
|
||||||
$fixtureDir = self::getFixturePath();
|
$fixtureDir = Fixture::path();
|
||||||
$stat = (yield file\stat("{$fixtureDir}/nonexistent"));
|
$stat = (yield File\stat("{$fixtureDir}/nonexistent"));
|
||||||
$this->assertNull($stat);
|
$this->assertNull($stat);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testExists() {
|
public function testExists() {
|
||||||
$this->lRun(function () {
|
$this->execute(function () {
|
||||||
$fixtureDir = self::getFixturePath();
|
$fixtureDir = Fixture::path();
|
||||||
$this->assertFalse(yield file\exists("{$fixtureDir}/nonexistent"));
|
$this->assertFalse(yield File\exists("{$fixtureDir}/nonexistent"));
|
||||||
$this->assertTrue(yield file\exists("{$fixtureDir}/small.txt"));
|
$this->assertTrue(yield File\exists("{$fixtureDir}/small.txt"));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSize() {
|
public function testSize() {
|
||||||
$this->lRun(function () {
|
$this->execute(function () {
|
||||||
$fixtureDir = self::getFixturePath();
|
$fixtureDir = Fixture::path();
|
||||||
$path = "{$fixtureDir}/small.txt";
|
$path = "{$fixtureDir}/small.txt";
|
||||||
$stat = (yield file\stat($path));
|
$stat = (yield File\stat($path));
|
||||||
$size = $stat["size"];
|
$size = $stat["size"];
|
||||||
file\StatCache::clear($path);
|
File\StatCache::clear($path);
|
||||||
$this->assertSame($size, (yield file\size($path)));
|
$this->assertSame($size, (yield File\size($path)));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,10 +116,10 @@ abstract class DriverTest extends TestCase {
|
|||||||
* @expectedException \Amp\File\FilesystemException
|
* @expectedException \Amp\File\FilesystemException
|
||||||
*/
|
*/
|
||||||
public function testSizeFailsOnNonexistentPath() {
|
public function testSizeFailsOnNonexistentPath() {
|
||||||
$this->lRun(function () {
|
$this->execute(function () {
|
||||||
$fixtureDir = self::getFixturePath();
|
$fixtureDir = Fixture::path();
|
||||||
$path = "{$fixtureDir}/nonexistent";
|
$path = "{$fixtureDir}/nonexistent";
|
||||||
yield file\size($path);
|
yield File\size($path);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,118 +127,118 @@ abstract class DriverTest extends TestCase {
|
|||||||
* @expectedException \Amp\File\FilesystemException
|
* @expectedException \Amp\File\FilesystemException
|
||||||
*/
|
*/
|
||||||
public function testSizeFailsOnDirectoryPath() {
|
public function testSizeFailsOnDirectoryPath() {
|
||||||
$this->lRun(function () {
|
$this->execute(function () {
|
||||||
$fixtureDir = self::getFixturePath();
|
$fixtureDir = Fixture::path();
|
||||||
$path = "{$fixtureDir}/dir";
|
$path = "{$fixtureDir}/dir";
|
||||||
$this->assertTrue(yield file\isdir($path));
|
$this->assertTrue(yield File\isdir($path));
|
||||||
file\StatCache::clear($path);
|
File\StatCache::clear($path);
|
||||||
yield file\size($path);
|
yield File\size($path);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIsdirResolvesTrueOnDirectoryPath() {
|
public function testIsdirResolvesTrueOnDirectoryPath() {
|
||||||
$this->lRun(function () {
|
$this->execute(function () {
|
||||||
$fixtureDir = self::getFixturePath();
|
$fixtureDir = Fixture::path();
|
||||||
$path = "{$fixtureDir}/dir";
|
$path = "{$fixtureDir}/dir";
|
||||||
$this->assertTrue(yield file\isdir($path));
|
$this->assertTrue(yield File\isdir($path));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIsdirResolvesFalseOnFilePath() {
|
public function testIsdirResolvesFalseOnFilePath() {
|
||||||
$this->lRun(function () {
|
$this->execute(function () {
|
||||||
$fixtureDir = self::getFixturePath();
|
$fixtureDir = Fixture::path();
|
||||||
$path = "{$fixtureDir}/small.txt";
|
$path = "{$fixtureDir}/small.txt";
|
||||||
$this->assertFalse(yield file\isdir($path));
|
$this->assertFalse(yield File\isdir($path));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIsdirResolvesFalseOnNonexistentPath() {
|
public function testIsdirResolvesFalseOnNonexistentPath() {
|
||||||
$this->lRun(function () {
|
$this->execute(function () {
|
||||||
$fixtureDir = self::getFixturePath();
|
$fixtureDir = Fixture::path();
|
||||||
$path = "{$fixtureDir}/nonexistent";
|
$path = "{$fixtureDir}/nonexistent";
|
||||||
$this->assertFalse(yield file\isdir($path));
|
$this->assertFalse(yield File\isdir($path));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIsfileResolvesTrueOnFilePath() {
|
public function testIsfileResolvesTrueOnFilePath() {
|
||||||
$this->lRun(function () {
|
$this->execute(function () {
|
||||||
$fixtureDir = self::getFixturePath();
|
$fixtureDir = Fixture::path();
|
||||||
$path = "{$fixtureDir}/small.txt";
|
$path = "{$fixtureDir}/small.txt";
|
||||||
$this->assertTrue(yield file\isfile($path));
|
$this->assertTrue(yield File\isfile($path));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIsfileResolvesFalseOnDirectoryPath() {
|
public function testIsfileResolvesFalseOnDirectoryPath() {
|
||||||
$this->lRun(function () {
|
$this->execute(function () {
|
||||||
$fixtureDir = self::getFixturePath();
|
$fixtureDir = Fixture::path();
|
||||||
$path = "{$fixtureDir}/dir";
|
$path = "{$fixtureDir}/dir";
|
||||||
$this->assertFalse(yield file\isfile($path));
|
$this->assertFalse(yield File\isfile($path));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIsfileResolvesFalseOnNonexistentPath() {
|
public function testIsfileResolvesFalseOnNonexistentPath() {
|
||||||
$this->lRun(function () {
|
$this->execute(function () {
|
||||||
$fixtureDir = self::getFixturePath();
|
$fixtureDir = Fixture::path();
|
||||||
$path = "{$fixtureDir}/nonexistent";
|
$path = "{$fixtureDir}/nonexistent";
|
||||||
$this->assertFalse(yield file\isfile($path));
|
$this->assertFalse(yield File\isfile($path));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRename() {
|
public function testRename() {
|
||||||
$this->lRun(function () {
|
$this->execute(function () {
|
||||||
$fixtureDir = self::getFixturePath();
|
$fixtureDir = Fixture::path();
|
||||||
|
|
||||||
$contents1 = "rename test";
|
$contents1 = "rename test";
|
||||||
$old = "{$fixtureDir}/rename1.txt";
|
$old = "{$fixtureDir}/rename1.txt";
|
||||||
$new = "{$fixtureDir}/rename2.txt";
|
$new = "{$fixtureDir}/rename2.txt";
|
||||||
|
|
||||||
yield file\put($old, $contents1);
|
yield File\put($old, $contents1);
|
||||||
yield file\rename($old, $new);
|
yield File\rename($old, $new);
|
||||||
$contents2 = (yield file\get($new));
|
$contents2 = (yield File\get($new));
|
||||||
yield file\unlink($new);
|
yield File\unlink($new);
|
||||||
|
|
||||||
$this->assertSame($contents1, $contents2);
|
$this->assertSame($contents1, $contents2);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUnlink() {
|
public function testUnlink() {
|
||||||
$this->lRun(function () {
|
$this->execute(function () {
|
||||||
$fixtureDir = self::getFixturePath();
|
$fixtureDir = Fixture::path();
|
||||||
$toUnlink = "{$fixtureDir}/unlink";
|
$toUnlink = "{$fixtureDir}/unlink";
|
||||||
yield file\put($toUnlink, "unlink me");
|
yield File\put($toUnlink, "unlink me");
|
||||||
yield file\unlink($toUnlink);
|
yield File\unlink($toUnlink);
|
||||||
$this->assertNull(yield file\stat($toUnlink));
|
$this->assertNull(yield File\stat($toUnlink));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMkdirRmdir() {
|
public function testMkdirRmdir() {
|
||||||
$this->lRun(function () {
|
$this->execute(function () {
|
||||||
$fixtureDir = self::getFixturePath();
|
$fixtureDir = Fixture::path();
|
||||||
|
|
||||||
$dir = "{$fixtureDir}/newdir";
|
$dir = "{$fixtureDir}/newdir";
|
||||||
|
|
||||||
yield file\mkdir($dir);
|
yield File\mkdir($dir);
|
||||||
$stat = yield file\stat($dir);
|
$stat = yield File\stat($dir);
|
||||||
$this->assertTrue(($stat["mode"] & 0777) === 0644);
|
$this->assertTrue(($stat["mode"] & 0777) === 0644);
|
||||||
yield file\rmdir($dir);
|
yield File\rmdir($dir);
|
||||||
$this->assertNull(yield file\stat($dir));
|
$this->assertNull(yield File\stat($dir));
|
||||||
|
|
||||||
$dir = "{$fixtureDir}/newdir/with/recursive/creation";
|
$dir = "{$fixtureDir}/newdir/with/recursive/creation";
|
||||||
|
|
||||||
yield file\mkdir($dir, 0764, true); // the umask is 022 by default
|
yield File\mkdir($dir, 0764, true); // the umask is 022 by default
|
||||||
$stat = yield file\stat($dir);
|
$stat = yield File\stat($dir);
|
||||||
$this->assertTrue(($stat["mode"] & 0777) == 0744);
|
$this->assertTrue(($stat["mode"] & 0777) == 0744);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMtime() {
|
public function testMtime() {
|
||||||
$this->lRun(function () {
|
$this->execute(function () {
|
||||||
$fixtureDir = self::getFixturePath();
|
$fixtureDir = Fixture::path();
|
||||||
$path = "{$fixtureDir}/small.txt";
|
$path = "{$fixtureDir}/small.txt";
|
||||||
$stat = (yield file\stat($path));
|
$stat = (yield File\stat($path));
|
||||||
$statMtime = $stat["mtime"];
|
$statMtime = $stat["mtime"];
|
||||||
file\StatCache::clear($path);
|
File\StatCache::clear($path);
|
||||||
$this->assertSame($statMtime, (yield file\mtime($path)));
|
$this->assertSame($statMtime, (yield File\mtime($path)));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -293,21 +246,21 @@ abstract class DriverTest extends TestCase {
|
|||||||
* @expectedException \Amp\File\FilesystemException
|
* @expectedException \Amp\File\FilesystemException
|
||||||
*/
|
*/
|
||||||
public function testMtimeFailsOnNonexistentPath() {
|
public function testMtimeFailsOnNonexistentPath() {
|
||||||
$this->lRun(function () {
|
$this->execute(function () {
|
||||||
$fixtureDir = self::getFixturePath();
|
$fixtureDir = Fixture::path();
|
||||||
$path = "{$fixtureDir}/nonexistent";
|
$path = "{$fixtureDir}/nonexistent";
|
||||||
yield file\mtime($path);
|
yield File\mtime($path);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAtime() {
|
public function testAtime() {
|
||||||
$this->lRun(function () {
|
$this->execute(function () {
|
||||||
$fixtureDir = self::getFixturePath();
|
$fixtureDir = Fixture::path();
|
||||||
$path = "{$fixtureDir}/small.txt";
|
$path = "{$fixtureDir}/small.txt";
|
||||||
$stat = (yield file\stat($path));
|
$stat = (yield File\stat($path));
|
||||||
$statAtime = $stat["atime"];
|
$statAtime = $stat["atime"];
|
||||||
file\StatCache::clear($path);
|
File\StatCache::clear($path);
|
||||||
$this->assertSame($statAtime, (yield file\atime($path)));
|
$this->assertSame($statAtime, (yield File\atime($path)));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -315,21 +268,21 @@ abstract class DriverTest extends TestCase {
|
|||||||
* @expectedException \Amp\File\FilesystemException
|
* @expectedException \Amp\File\FilesystemException
|
||||||
*/
|
*/
|
||||||
public function testAtimeFailsOnNonexistentPath() {
|
public function testAtimeFailsOnNonexistentPath() {
|
||||||
$this->lRun(function () {
|
$this->execute(function () {
|
||||||
$fixtureDir = self::getFixturePath();
|
$fixtureDir = Fixture::path();
|
||||||
$path = "{$fixtureDir}/nonexistent";
|
$path = "{$fixtureDir}/nonexistent";
|
||||||
yield file\atime($path);
|
yield File\atime($path);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCtime() {
|
public function testCtime() {
|
||||||
$this->lRun(function () {
|
$this->execute(function () {
|
||||||
$fixtureDir = self::getFixturePath();
|
$fixtureDir = Fixture::path();
|
||||||
$path = "{$fixtureDir}/small.txt";
|
$path = "{$fixtureDir}/small.txt";
|
||||||
$stat = (yield file\stat($path));
|
$stat = (yield File\stat($path));
|
||||||
$statCtime = $stat["ctime"];
|
$statCtime = $stat["ctime"];
|
||||||
file\StatCache::clear($path);
|
File\StatCache::clear($path);
|
||||||
$this->assertSame($statCtime, (yield file\ctime($path)));
|
$this->assertSame($statCtime, (yield File\ctime($path)));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -337,10 +290,10 @@ abstract class DriverTest extends TestCase {
|
|||||||
* @expectedException \Amp\File\FilesystemException
|
* @expectedException \Amp\File\FilesystemException
|
||||||
*/
|
*/
|
||||||
public function testCtimeFailsOnNonexistentPath() {
|
public function testCtimeFailsOnNonexistentPath() {
|
||||||
$this->lRun(function () {
|
$this->execute(function () {
|
||||||
$fixtureDir = self::getFixturePath();
|
$fixtureDir = Fixture::path();
|
||||||
$path = "{$fixtureDir}/nonexistent";
|
$path = "{$fixtureDir}/nonexistent";
|
||||||
yield file\ctime($path);
|
yield File\ctime($path);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -348,18 +301,18 @@ abstract class DriverTest extends TestCase {
|
|||||||
* @group slow
|
* @group slow
|
||||||
*/
|
*/
|
||||||
public function testTouch() {
|
public function testTouch() {
|
||||||
$this->lRun(function () {
|
$this->execute(function () {
|
||||||
$fixtureDir = self::getFixturePath();
|
$fixtureDir = Fixture::path();
|
||||||
|
|
||||||
$touch = "{$fixtureDir}/touch";
|
$touch = "{$fixtureDir}/touch";
|
||||||
yield file\put($touch, "touch me");
|
yield File\put($touch, "touch me");
|
||||||
|
|
||||||
$oldStat = (yield file\stat($touch));
|
$oldStat = (yield File\stat($touch));
|
||||||
sleep(1);
|
sleep(1);
|
||||||
yield file\touch($touch);
|
yield File\touch($touch);
|
||||||
file\StatCache::clear($touch);
|
File\StatCache::clear($touch);
|
||||||
$newStat = (yield file\stat($touch));
|
$newStat = (yield File\stat($touch));
|
||||||
yield file\unlink($touch);
|
yield File\unlink($touch);
|
||||||
|
|
||||||
$this->assertTrue($newStat["atime"] > $oldStat["atime"]);
|
$this->assertTrue($newStat["atime"] > $oldStat["atime"]);
|
||||||
$this->assertTrue($newStat["mtime"] > $oldStat["mtime"]);
|
$this->assertTrue($newStat["mtime"] > $oldStat["mtime"]);
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
namespace Amp\File\Test;
|
namespace Amp\File\Test;
|
||||||
|
|
||||||
class EioDriverTest extends DriverTest {
|
class EioDriverTest extends DriverTest {
|
||||||
protected function lRun(callable $cb) {
|
protected function execute(callable $cb) {
|
||||||
if (\extension_loaded("eio")) {
|
if (\extension_loaded("eio")) {
|
||||||
\Amp\Loop::run(function() use ($cb) {
|
\Amp\Loop::run(function() use ($cb) {
|
||||||
\Amp\File\filesystem(new \Amp\File\EioDriver);
|
\Amp\File\filesystem(new \Amp\File\EioDriver);
|
||||||
|
@ -5,7 +5,7 @@ namespace Amp\File\Test;
|
|||||||
use Amp\File as file;
|
use Amp\File as file;
|
||||||
|
|
||||||
class EioHandleTest extends HandleTest {
|
class EioHandleTest extends HandleTest {
|
||||||
protected function lRun(callable $cb) {
|
protected function execute(callable $cb) {
|
||||||
if (\extension_loaded("eio")) {
|
if (\extension_loaded("eio")) {
|
||||||
\Amp\Loop::run(function() use ($cb) {
|
\Amp\Loop::run(function() use ($cb) {
|
||||||
\Amp\File\filesystem(new \Amp\File\EioDriver);
|
\Amp\File\filesystem(new \Amp\File\EioDriver);
|
||||||
@ -19,7 +19,7 @@ class EioHandleTest extends HandleTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testQueuedWritesOverrideEachOtherIfNotWaitedUpon() {
|
public function testQueuedWritesOverrideEachOtherIfNotWaitedUpon() {
|
||||||
$this->lRun(function () {
|
$this->execute(function () {
|
||||||
$path = Fixture::path() . "/write";
|
$path = Fixture::path() . "/write";
|
||||||
$handle = (yield file\open($path, "c+"));
|
$handle = (yield file\open($path, "c+"));
|
||||||
$this->assertSame(0, $handle->tell());
|
$this->assertSame(0, $handle->tell());
|
||||||
|
@ -2,28 +2,25 @@
|
|||||||
|
|
||||||
namespace Amp\File\Test;
|
namespace Amp\File\Test;
|
||||||
|
|
||||||
use Amp\File as file;
|
use Amp\File;
|
||||||
use Amp\PHPUnit\TestCase;
|
use Amp\PHPUnit\TestCase;
|
||||||
|
|
||||||
abstract class HandleTest extends TestCase {
|
abstract class HandleTest extends TestCase {
|
||||||
public static function setUpBeforeClass() {
|
protected function setUp() {
|
||||||
Fixture::init();
|
Fixture::init();
|
||||||
|
File\StatCache::clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function tearDownAfterClass() {
|
protected function tearDown() {
|
||||||
Fixture::clear();
|
Fixture::clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function setUp() {
|
abstract protected function execute(callable $cb);
|
||||||
file\StatCache::clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract protected function lRun(callable $cb);
|
|
||||||
|
|
||||||
public function testWrite() {
|
public function testWrite() {
|
||||||
$this->lRun(function () {
|
$this->execute(function () {
|
||||||
$path = Fixture::path() . "/write";
|
$path = Fixture::path() . "/write";
|
||||||
$handle = (yield file\open($path, "c+"));
|
$handle = yield File\open($path, "c+");
|
||||||
$this->assertSame(0, $handle->tell());
|
$this->assertSame(0, $handle->tell());
|
||||||
|
|
||||||
yield $handle->write("foo");
|
yield $handle->write("foo");
|
||||||
@ -35,35 +32,34 @@ abstract class HandleTest extends TestCase {
|
|||||||
$this->assertSame("foobar", $contents);
|
$this->assertSame("foobar", $contents);
|
||||||
|
|
||||||
yield $handle->close();
|
yield $handle->close();
|
||||||
yield file\unlink($path);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReadingToEof() {
|
public function testReadingToEof() {
|
||||||
$this->lRun(function () {
|
$this->execute(function () {
|
||||||
$handle = (yield file\open(__FILE__, "r"));
|
$handle = yield File\open(__FILE__, "r");
|
||||||
$contents = "";
|
$contents = "";
|
||||||
$position = 0;
|
$position = 0;
|
||||||
|
|
||||||
$stat = (yield file\stat(__FILE__));
|
$stat = yield File\stat(__FILE__);
|
||||||
$chunkSize = (int) \floor(($stat["size"] / 5));
|
$chunkSize = (int) \floor(($stat["size"] / 5));
|
||||||
|
|
||||||
while (!$handle->eof()) {
|
while (!$handle->eof()) {
|
||||||
$chunk = (yield $handle->read($chunkSize));
|
$chunk = yield $handle->read($chunkSize);
|
||||||
$contents .= $chunk;
|
$contents .= $chunk;
|
||||||
$position += \strlen($chunk);
|
$position += \strlen($chunk);
|
||||||
$this->assertSame($position, $handle->tell());
|
$this->assertSame($position, $handle->tell());
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->assertSame((yield file\get(__FILE__)), $contents);
|
$this->assertSame((yield File\get(__FILE__)), $contents);
|
||||||
|
|
||||||
yield $handle->close();
|
yield $handle->close();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testQueuedReads() {
|
public function testQueuedReads() {
|
||||||
$this->lRun(function () {
|
$this->execute(function () {
|
||||||
$handle = (yield file\open(__FILE__, "r"));
|
$handle = yield File\open(__FILE__, "r");
|
||||||
|
|
||||||
$contents = "";
|
$contents = "";
|
||||||
$read1 = $handle->read(10);
|
$read1 = $handle->read(10);
|
||||||
@ -73,7 +69,7 @@ abstract class HandleTest extends TestCase {
|
|||||||
$contents .= (yield $read1);
|
$contents .= (yield $read1);
|
||||||
$contents .= (yield $read2);
|
$contents .= (yield $read2);
|
||||||
|
|
||||||
$expected = \substr((yield file\get(__FILE__)), 0, 20);
|
$expected = \substr((yield File\get(__FILE__)), 0, 20);
|
||||||
$this->assertSame($expected, $contents);
|
$this->assertSame($expected, $contents);
|
||||||
|
|
||||||
yield $handle->close();
|
yield $handle->close();
|
||||||
@ -81,14 +77,14 @@ abstract class HandleTest extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testReadingFromOffset() {
|
public function testReadingFromOffset() {
|
||||||
$this->lRun(function () {
|
$this->execute(function () {
|
||||||
$handle = (yield file\open(__FILE__, "r"));
|
$handle = yield File\open(__FILE__, "r");
|
||||||
$this->assertSame(0, $handle->tell());
|
$this->assertSame(0, $handle->tell());
|
||||||
yield $handle->seek(10);
|
yield $handle->seek(10);
|
||||||
$this->assertSame(10, $handle->tell());
|
$this->assertSame(10, $handle->tell());
|
||||||
$chunk = (yield $handle->read(90));
|
$chunk = (yield $handle->read(90));
|
||||||
$this->assertSame(100, $handle->tell());
|
$this->assertSame(100, $handle->tell());
|
||||||
$expected = \substr((yield file\get(__FILE__)), 10, 90);
|
$expected = \substr((yield File\get(__FILE__)), 10, 90);
|
||||||
$this->assertSame($expected, $chunk);
|
$this->assertSame($expected, $chunk);
|
||||||
|
|
||||||
yield $handle->close();
|
yield $handle->close();
|
||||||
@ -99,9 +95,9 @@ abstract class HandleTest extends TestCase {
|
|||||||
* @expectedException \Error
|
* @expectedException \Error
|
||||||
*/
|
*/
|
||||||
public function testSeekThrowsOnInvalidWhence() {
|
public function testSeekThrowsOnInvalidWhence() {
|
||||||
$this->lRun(function () {
|
$this->execute(function () {
|
||||||
try {
|
try {
|
||||||
$handle = (yield file\open(__FILE__, "r"));
|
$handle = yield File\open(__FILE__, "r");
|
||||||
yield $handle->seek(0, 99999);
|
yield $handle->seek(0, 99999);
|
||||||
} finally {
|
} finally {
|
||||||
yield $handle->close();
|
yield $handle->close();
|
||||||
@ -110,8 +106,8 @@ abstract class HandleTest extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testSeekSetCur() {
|
public function testSeekSetCur() {
|
||||||
$this->lRun(function () {
|
$this->execute(function () {
|
||||||
$handle = (yield file\open(__FILE__, "r"));
|
$handle = yield File\open(__FILE__, "r");
|
||||||
$this->assertSame(0, $handle->tell());
|
$this->assertSame(0, $handle->tell());
|
||||||
yield $handle->seek(10);
|
yield $handle->seek(10);
|
||||||
$this->assertSame(10, $handle->tell());
|
$this->assertSame(10, $handle->tell());
|
||||||
@ -122,9 +118,9 @@ abstract class HandleTest extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testSeekSetEnd() {
|
public function testSeekSetEnd() {
|
||||||
$this->lRun(function () {
|
$this->execute(function () {
|
||||||
$size = (yield file\size(__FILE__));
|
$size = yield File\size(__FILE__);
|
||||||
$handle = (yield file\open(__FILE__, "r"));
|
$handle = yield File\open(__FILE__, "r");
|
||||||
$this->assertSame(0, $handle->tell());
|
$this->assertSame(0, $handle->tell());
|
||||||
yield $handle->seek(-10, \SEEK_END);
|
yield $handle->seek(-10, \SEEK_END);
|
||||||
$this->assertSame($size - 10, $handle->tell());
|
$this->assertSame($size - 10, $handle->tell());
|
||||||
@ -133,24 +129,24 @@ abstract class HandleTest extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testPath() {
|
public function testPath() {
|
||||||
$this->lRun(function () {
|
$this->execute(function () {
|
||||||
$handle = (yield file\open(__FILE__, "r"));
|
$handle = yield File\open(__FILE__, "r");
|
||||||
$this->assertSame(__FILE__, $handle->path());
|
$this->assertSame(__FILE__, $handle->path());
|
||||||
yield $handle->close();
|
yield $handle->close();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMode() {
|
public function testMode() {
|
||||||
$this->lRun(function () {
|
$this->execute(function () {
|
||||||
$handle = (yield file\open(__FILE__, "r"));
|
$handle = yield File\open(__FILE__, "r");
|
||||||
$this->assertSame("r", $handle->mode());
|
$this->assertSame("r", $handle->mode());
|
||||||
yield $handle->close();
|
yield $handle->close();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testClose() {
|
public function testClose() {
|
||||||
$this->lRun(function () {
|
$this->execute(function () {
|
||||||
$handle = (yield file\open(__FILE__, "r"));
|
$handle = yield File\open(__FILE__, "r");
|
||||||
yield $handle->close();
|
yield $handle->close();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ use Amp\Parallel\Worker\DefaultPool;
|
|||||||
use function Amp\call;
|
use function Amp\call;
|
||||||
|
|
||||||
class ParallelDriverTest extends DriverTest {
|
class ParallelDriverTest extends DriverTest {
|
||||||
protected function lRun(callable $cb) {
|
protected function execute(callable $cb) {
|
||||||
Loop::run(function() use ($cb) {
|
Loop::run(function() use ($cb) {
|
||||||
$pool = new DefaultPool;
|
$pool = new DefaultPool;
|
||||||
$pool->start();
|
$pool->start();
|
||||||
|
@ -8,7 +8,7 @@ use Amp\Parallel\Worker\DefaultPool;
|
|||||||
use function Amp\call;
|
use function Amp\call;
|
||||||
|
|
||||||
class ParallelHandleTest extends HandleTest {
|
class ParallelHandleTest extends HandleTest {
|
||||||
protected function lRun(callable $cb) {
|
protected function execute(callable $cb) {
|
||||||
Loop::run(function() use ($cb) {
|
Loop::run(function() use ($cb) {
|
||||||
$pool = new DefaultPool;
|
$pool = new DefaultPool;
|
||||||
$pool->start();
|
$pool->start();
|
||||||
|
@ -5,7 +5,7 @@ namespace Amp\File\Test;
|
|||||||
use Amp\Loop;
|
use Amp\Loop;
|
||||||
|
|
||||||
class UvDriverTest extends DriverTest {
|
class UvDriverTest extends DriverTest {
|
||||||
protected function lRun(callable $cb) {
|
protected function execute(callable $cb) {
|
||||||
if (\extension_loaded("uv")) {
|
if (\extension_loaded("uv")) {
|
||||||
$loop = new Loop\UvDriver;
|
$loop = new Loop\UvDriver;
|
||||||
Loop::set($loop);
|
Loop::set($loop);
|
||||||
|
@ -6,7 +6,7 @@ use Amp\Loop;
|
|||||||
use Amp\File as file;
|
use Amp\File as file;
|
||||||
|
|
||||||
class UvHandleTest extends HandleTest {
|
class UvHandleTest extends HandleTest {
|
||||||
protected function lRun(callable $cb) {
|
protected function execute(callable $cb) {
|
||||||
if (\extension_loaded("uv")) {
|
if (\extension_loaded("uv")) {
|
||||||
$loop = new Loop\UvDriver;
|
$loop = new Loop\UvDriver;
|
||||||
Loop::set($loop);
|
Loop::set($loop);
|
||||||
@ -22,7 +22,7 @@ class UvHandleTest extends HandleTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testQueuedWritesOverrideEachOtherIfNotWaitedUpon() {
|
public function testQueuedWritesOverrideEachOtherIfNotWaitedUpon() {
|
||||||
$this->lRun(function () {
|
$this->execute(function () {
|
||||||
$path = Fixture::path() . "/write";
|
$path = Fixture::path() . "/write";
|
||||||
$handle = (yield file\open($path, "c+"));
|
$handle = (yield file\open($path, "c+"));
|
||||||
$this->assertSame(0, $handle->tell());
|
$this->assertSame(0, $handle->tell());
|
||||||
|
Loading…
Reference in New Issue
Block a user