. * */ namespace Test; /** * Class StreamWrappersTest * * @group DB */ class StreamWrappersTest extends \Test\TestCase { private static $trashBinStatus; public static function setUpBeforeClass() { self::$trashBinStatus = \OC_App::isEnabled('files_trashbin'); \OC_App::disable('files_trashbin'); } public static function tearDownAfterClass() { if (self::$trashBinStatus) { (new \OC_App())->enable('files_trashbin'); } } public function testCloseStream() { //ensure all basic stream stuff works $sourceFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; $tmpFile = \OC::$server->getTempManager()->getTemporaryFile('.txt'); $file = 'close://' . $tmpFile; $this->assertTrue(file_exists($file)); file_put_contents($file, file_get_contents($sourceFile)); $this->assertEquals(file_get_contents($sourceFile), file_get_contents($file)); unlink($file); clearstatcache(); $this->assertFalse(file_exists($file)); //test callback $tmpFile = \OC::$server->getTempManager()->getTemporaryFile('.txt'); $file = 'close://' . $tmpFile; $actual = false; $callback = function($path) use (&$actual) { $actual = $path; }; \OC\Files\Stream\Close::registerCallback($tmpFile, $callback); $fh = fopen($file, 'w'); fwrite($fh, 'asd'); fclose($fh); $this->assertSame($tmpFile, $actual); } }