getReactor()->run(function($reactor) { $fs = $this->getFilesystem($reactor); $descriptor = (yield $fs->open(__DIR__ . "/fixture/small.txt", Filesystem::READ)); $this->assertInstanceOf("Amp\Fs\Descriptor", $descriptor); }); } public function testScandir() { $this->getReactor()->run(function($reactor) { $fs = $this->getFilesystem($reactor); $actual = (yield $fs->scandir(__DIR__ . "/fixture")); $expected = ["dir", "small.txt"]; $this->assertSame($expected, $actual); }); } public function testSymlink() { $this->getReactor()->run(function($reactor) { $fs = $this->getFilesystem($reactor); $target = __DIR__ . "/fixture/small.txt"; $link = __DIR__ . "/fixture/symlink.txt"; $this->assertTrue(yield $fs->symlink($target, $link)); $this->assertTrue(is_link($link)); yield $fs->unlink($link); }); } public function testLstat() { $this->getReactor()->run(function($reactor) { $fs = $this->getFilesystem($reactor); $target = __DIR__ . "/fixture/small.txt"; $link = __DIR__ . "/fixture/symlink.txt"; $this->assertTrue(yield $fs->symlink($target, $link)); $this->assertTrue(is_array(yield $fs->lstat($link))); yield $fs->unlink($link); }); } /** * @expectedException RuntimeException */ public function testOpenFailsOnNonexistentFile() { $this->getReactor()->run(function($reactor) { $fs = $this->getFilesystem($reactor); $descriptor = (yield $fs->open(__DIR__ . "/fixture/nonexistent", Filesystem::READ)); $this->assertInstanceOf("Amp\Fs\Descriptor", $descriptor); }); } public function testStatForFile() { $this->getReactor()->run(function($reactor) { $fs = $this->getFilesystem($reactor); $stat = (yield $fs->stat(__DIR__ . "/fixture/small.txt")); $this->assertInternalType("array", $stat); }); } public function testStatForDirectory() { $this->getReactor()->run(function($reactor) { $fs = $this->getFilesystem($reactor); $stat = (yield $fs->stat(__DIR__ . "/fixture/dir")); $this->assertInternalType("array", $stat); }); } public function testStatForNonexistentPath() { $this->getReactor()->run(function($reactor) { $fs = $this->getFilesystem($reactor); $stat = (yield $fs->stat(__DIR__ . "/fixture/nonexistent")); $this->assertNull($stat); }); } public function testRename() { $this->getReactor()->run(function($reactor) { $fs = $this->getFilesystem($reactor); $contents1 = "rename test"; $old = __DIR__ . "/fixture/rename1.txt"; $new = __DIR__ . "/fixture/rename2.txt"; yield $fs->put($old, $contents1); yield $fs->rename($old, $new); $contents2 = (yield $fs->get($new)); yield $fs->unlink($new); $this->assertSame($contents1, $contents2); }); } public function testUnlink() { $this->getReactor()->run(function($reactor) { $fs = $this->getFilesystem($reactor); $toUnlink = __DIR__ . "/fixture/unlink"; yield $fs->put($toUnlink, "unlink me"); $this->assertTrue((bool) (yield $fs->stat($toUnlink))); yield $fs->unlink($toUnlink); $this->assertNull(yield $fs->stat($toUnlink)); }); } public function testMkdirRmdir() { $this->getReactor()->run(function($reactor) { $fs = $this->getFilesystem($reactor); $dir = __DIR__ . "/fixture/newdir"; yield $fs->mkdir($dir); $stat = (yield $fs->stat($dir)); $this->assertTrue($stat["isdir"]); $this->assertFalse($stat["isfile"]); yield $fs->rmdir($dir); $this->assertNull(yield $fs->stat($dir)); }); } /** * @group slow */ public function testTouch() { $this->getReactor()->run(function($reactor) { $fs = $this->getFilesystem($reactor); $touch = __DIR__ . "/fixture/touch"; yield $fs->put($touch, "touch me"); $oldStat = (yield $fs->stat($touch)); sleep(1); yield $fs->touch($touch); $newStat = (yield $fs->stat($touch)); yield $fs->unlink($touch); $this->assertTrue($newStat["atime"] > $oldStat["atime"]); $this->assertTrue($newStat["mtime"] > $oldStat["mtime"]); }); } }