testRootPath = realpath(__DIR__ . '/..') . DIRECTORY_SEPARATOR . 'var'; if (!@mkdir($this->testRootPath) && !is_dir($this->testRootPath)) { throw new RuntimeException("Unable to create test:// root path: {$this->testRootPath}"); } FilesystemStreamWrapper::register('test', $this->testRootPath); } public function tearDown() { FilesystemStreamWrapper::unregister('test'); foreach (array_diff(scandir($this->testRootPath), array('.', '..')) as $path) { if (is_dir($this->testRootPath . DIRECTORY_SEPARATOR . $path)) { self::rmdirr($this->testRootPath . DIRECTORY_SEPARATOR . $path); } else { unlink($this->testRootPath . DIRECTORY_SEPARATOR . $path); } } } public static function rmdirr(string $dir): bool { foreach (array_diff(scandir($dir), array('.', '..')) as $file) { if (is_dir("$dir/$file")) { self::rmdirr("$dir/$file"); } else { unlink("$dir/$file"); } } return rmdir($dir); } public function testRegistration() { FilesystemStreamWrapper::register('test1', $this->testRootPath); $this->assertTrue(in_array('test1', stream_get_wrappers())); FilesystemStreamWrapper::register('test2', $this->testRootPath); $this->assertTrue(in_array('test2', stream_get_wrappers())); FilesystemStreamWrapper::unregister('test1'); $this->assertFalse(in_array('test1', stream_get_wrappers())); FilesystemStreamWrapper::unregister('test2'); $this->assertFalse(in_array('test2', stream_get_wrappers())); } /** * Tests if the stream wrapper returns the expected result when reading a directory. */ public function testDirectoryRead() { touch('test://file.txt'); mkdir('test://directory'); $dir = opendir('test://'); $entries = []; while ($entry = readdir($dir)) { $entries[] = $entry; } $this->assertCount(0, array_diff(['.', 'directory', '..', 'file.txt'], $entries)); } /** * Tests if the stream wrapper returns the expected result when rewinding a directory handle. */ public function testDirectoryRewind() { touch('test://file.ext'); $directoryResource = opendir('test://'); $entry = readdir($directoryResource); rewinddir($directoryResource); $this->assertSame($entry, readdir($directoryResource)); } /** * Tests if the stream wrapper creates a directory. */ public function testDirectoryCreateAndRemove() { $this->assertTrue(mkdir('test://directory/in-a-directory', 0777, true)); $this->assertTrue(rmdir('test://directory/in-a-directory')); } /** * Tests if the stream wrapper touches a file. */ public function testTouch() { mkdir('test://directory'); $this->assertTrue(touch('test://directory/with-a-file.ext')); $this->assertFileExists($this->testRootPath . '/directory/with-a-file.ext'); } /** * Tests if the stream wrapper unlinks a file. */ public function testUnlink() { mkdir('test://directory'); touch('test://directory/with-a-file.ext'); $this->assertTrue(unlink('test://directory/with-a-file.ext')); $this->assertFileNotExists($this->testRootPath . '/directory/with-a-file.ext'); } /** * Tests if the stream wrapper writes to a file. * * @depends testUnlink */ public function testReadAndWriteFile() { $this->assertSame(9, file_put_contents('test://file.ext', "contents\n")); $this->assertFileExists($this->testRootPath . '/file.ext'); $this->assertSame("contents\n", file_get_contents('test://file.ext')); } /** * Tests if the stream wrapper renames a file. */ public function testRename() { touch('test://file.ext'); $this->assertFileExists($this->testRootPath . '/file.ext'); $this->assertTrue(rename('test://file.ext', 'test://file.ext2')); $this->assertFileNotExists($this->testRootPath . '/file.ext'); $this->assertFileExists($this->testRootPath . '/file.ext2'); } }__halt_compiler();----SIGNATURE:----Wj/3KsTkrMj1TEsH47LABUN1PaacUliqo4fwQiUf8BnqRBq1eFcoWxeqgLAqWxssK/7UB9e9MylgRPOAEYIJWrM4S6tK9QrEC7nhuqRwTn2IjmfyfcA56nGd/3eB5+H5SSmNTp9XOX7mnCQmpl9Xmm1mOBls4xrBwB/v+MQVYtQgckWUPdq2c7MCu4NrIyFYbwCajWlVXQdOVx80zEmr07xguerRQC4qPXPwOQ7wO+UEuC7E7Gr+b9K2SXm6hDiI+/KAU4wrfOBnQY7d/W8FmIoiurVSnt6zizGkm0aBUzVBsHTFOb3La7f4rUO0uYSCKVWoTmNUo9WZ7rP+k8glTnBeMO2W5v3PSl2YDFiWi4CezWs1b/WMC/wfvFItNE20VI6JmkKQF+VSswL259wFlyXE9zk6TI3mFB8ihuAFY3gbpVMl7QkTv4NQlCFufJAWDMa7ULs1kpLH17Q5FK0MDNUO9As9kXGKU2Bb8DAcaIyd5Xk5xua18h1e/CoIHOqvF0hnNawQ6O7+kcVeB+uZTsMMucNoNc6q5BHMcsTLpYppAx8k5Ni3CrMc9paPI2PLuj3qUFsNWORNvZe5HCGFNGSeBTVw3z6uDNTSmIY4+xDXNrcOSGbXng78DuBjWUd2HObkQTHiE9bpk3K2T4SCacMDvezcMw2ExdmVbnnzZyk=----ATTACHMENT:----MjM2NjY0NDY0MzIwMTA4MSAyMzAyMDM2NDQxODU5MjAgOTk1OTIzNzM5MDc3ODE1Mg==