public function testCloseStream() { //ensure all basic stream stuff works $sourceFile = OC::$SERVERROOT . '/tests/data/lorem.txt'; $tmpFile = OC_Helper::TmpFile('.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_Helper::TmpFile('.txt'); $file = 'close://' . $tmpFile; \OC\Files\Stream\Close::registerCallback($tmpFile, array('Test_StreamWrappers', 'closeCallBack')); $fh = fopen($file, 'w'); fwrite($fh, 'asd'); try { fclose($fh); $this->fail('Expected exception'); } catch (Exception $e) { $path = $e->getMessage(); $this->assertEquals($path, $tmpFile); } }
public function testCloseStream() { //ensure all basic stream stuff works $sourceFile = OC::$SERVERROOT . '/tests/data/lorem.txt'; $tmpFile = OC_Helper::TmpFile('.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_Helper::TmpFile('.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); }