assertSame($expected, $actual); }); } /** * @expectedException \Amp\File\FilesystemException */ public function testScandirThrowsIfPathNotADirectory() { amp\run(function () { (yield file\scandir(__FILE__)); }); } /** * @expectedException \Amp\File\FilesystemException */ public function testScandirThrowsIfPathDoesntExist() { amp\run(function () { $path = self::getFixturePath() . "/nonexistent"; (yield file\scandir($path)); }); } public function testSymlink() { amp\run(function () { $fixtureDir = self::getFixturePath(); $original = "{$fixtureDir}/small.txt"; $link = "{$fixtureDir}/symlink.txt"; $this->assertTrue(yield file\symlink($original, $link)); $this->assertTrue(\is_link($link)); yield file\unlink($link); }); } public function testLstat() { amp\run(function () { $fixtureDir = self::getFixturePath(); $target = "{$fixtureDir}/small.txt"; $link = "{$fixtureDir}/symlink.txt"; $this->assertTrue(yield file\symlink($target, $link)); $this->assertTrue(is_array(yield file\lstat($link))); yield file\unlink($link); }); } public function testFileStat() { amp\run(function () { $fixtureDir = self::getFixturePath(); $stat = (yield file\stat("{$fixtureDir}/small.txt")); $this->assertInternalType("array", $stat); }); } public function testDirStat() { amp\run(function () { $fixtureDir = self::getFixturePath(); $stat = (yield file\stat("{$fixtureDir}/dir")); $this->assertInternalType("array", $stat); }); } public function testNonexistentPathStatResolvesToNull() { amp\run(function () { $fixtureDir = self::getFixturePath(); $stat = (yield file\stat("{$fixtureDir}/nonexistent")); $this->assertNull($stat); }); } public function testExists() { amp\run(function () { $fixtureDir = self::getFixturePath(); $this->assertFalse(yield file\exists("{$fixtureDir}/nonexistent")); $this->assertTrue(yield file\exists("{$fixtureDir}/small.txt")); }); } public function testSize() { amp\run(function () { $fixtureDir = self::getFixturePath(); $path = "{$fixtureDir}/small.txt"; $stat = (yield file\stat($path)); $size = $stat["size"]; file\StatCache::clear($path); $this->assertSame($size, (yield file\size($path))); }); } /** * @expectedException \Amp\File\FilesystemException */ public function testSizeFailsOnNonexistentPath() { amp\run(function () { $fixtureDir = self::getFixturePath(); $path = "{$fixtureDir}/nonexistent"; yield file\size($path); }); } /** * @expectedException \Amp\File\FilesystemException */ public function testSizeFailsOnDirectoryPath() { amp\run(function () { $fixtureDir = self::getFixturePath(); $path = "{$fixtureDir}/dir"; $this->assertTrue(yield file\isdir($path)); file\StatCache::clear($path); yield file\size($path); }); } public function testIsdirResolvesTrueOnDirectoryPath() { amp\run(function () { $fixtureDir = self::getFixturePath(); $path = "{$fixtureDir}/dir"; $this->assertTrue(yield file\isdir($path)); }); } public function testIsdirResolvesFalseOnFilePath() { amp\run(function () { $fixtureDir = self::getFixturePath(); $path = "{$fixtureDir}/small.txt"; $this->assertFalse(yield file\isdir($path)); }); } public function testIsdirResolvesFalseOnNonexistentPath() { amp\run(function () { $fixtureDir = self::getFixturePath(); $path = "{$fixtureDir}/nonexistent"; $this->assertFalse(yield file\isdir($path)); }); } public function testIsfileResolvesTrueOnFilePath() { amp\run(function () { $fixtureDir = self::getFixturePath(); $path = "{$fixtureDir}/small.txt"; $this->assertTrue(yield file\isfile($path)); }); } public function testIsfileResolvesFalseOnDirectoryPath() { amp\run(function () { $fixtureDir = self::getFixturePath(); $path = "{$fixtureDir}/dir"; $this->assertFalse(yield file\isfile($path)); }); } public function testIsfileResolvesFalseOnNonexistentPath() { amp\run(function () { $fixtureDir = self::getFixturePath(); $path = "{$fixtureDir}/nonexistent"; $this->assertFalse(yield file\isfile($path)); }); } public function testRename() { amp\run(function () { $fixtureDir = self::getFixturePath(); $contents1 = "rename test"; $old = "{$fixtureDir}/rename1.txt"; $new = "{$fixtureDir}/rename2.txt"; yield file\put($old, $contents1); yield file\rename($old, $new); $contents2 = (yield file\get($new)); yield file\unlink($new); $this->assertSame($contents1, $contents2); }); } public function testUnlink() { amp\run(function () { $fixtureDir = self::getFixturePath(); $toUnlink = "{$fixtureDir}/unlink"; yield file\put($toUnlink, "unlink me"); $this->assertTrue((bool) (yield file\stat($toUnlink))); yield file\unlink($toUnlink); $this->assertNull(yield file\stat($toUnlink)); }); } public function testMkdirRmdir() { amp\run(function () { $fixtureDir = self::getFixturePath(); $dir = "{$fixtureDir}/newdir"; yield file\mkdir($dir); $this->assertNotNull(yield file\stat($dir)); yield file\rmdir($dir); $this->assertNull(yield file\stat($dir)); $dir = "{$fixtureDir}/newdir/with/recursive/creation"; yield file\mkdir($dir, 0744, true); $this->assertNotNull(yield file\stat($dir)); }); } public function testMtime() { amp\run(function () { $fixtureDir = self::getFixturePath(); $path = "{$fixtureDir}/small.txt"; $stat = (yield file\stat($path)); $statMtime = $stat["mtime"]; file\StatCache::clear($path); $this->assertSame($statMtime, (yield file\mtime($path))); }); } /** * @expectedException \Amp\File\FilesystemException */ public function testMtimeFailsOnNonexistentPath() { amp\run(function () { $fixtureDir = self::getFixturePath(); $path = "{$fixtureDir}/nonexistent"; yield file\mtime($path); }); } public function testAtime() { amp\run(function () { $fixtureDir = self::getFixturePath(); $path = "{$fixtureDir}/small.txt"; $stat = (yield file\stat($path)); $statAtime = $stat["atime"]; file\StatCache::clear($path); $this->assertSame($statAtime, (yield file\atime($path))); }); } /** * @expectedException \Amp\File\FilesystemException */ public function testAtimeFailsOnNonexistentPath() { amp\run(function () { $fixtureDir = self::getFixturePath(); $path = "{$fixtureDir}/nonexistent"; yield file\atime($path); }); } public function testCtime() { amp\run(function () { $fixtureDir = self::getFixturePath(); $path = "{$fixtureDir}/small.txt"; $stat = (yield file\stat($path)); $statCtime = $stat["ctime"]; file\StatCache::clear($path); $this->assertSame($statCtime, (yield file\ctime($path))); }); } /** * @expectedException \Amp\File\FilesystemException */ public function testCtimeFailsOnNonexistentPath() { amp\run(function () { $fixtureDir = self::getFixturePath(); $path = "{$fixtureDir}/nonexistent"; yield file\ctime($path); }); } /** * @group slow */ public function testTouch() { amp\run(function () { $fixtureDir = self::getFixturePath(); $touch = "{$fixtureDir}/touch"; yield file\put($touch, "touch me"); $oldStat = (yield file\stat($touch)); sleep(1); yield file\touch($touch); file\StatCache::clear($touch); $newStat = (yield file\stat($touch)); yield file\unlink($touch); $this->assertTrue($newStat["atime"] > $oldStat["atime"]); $this->assertTrue($newStat["mtime"] > $oldStat["mtime"]); }); } }