public function testFilePutContentsWriteError() { // Force error by simulating full disk vfsStream::setQuota(3); $filename = $this->_root->url() . '/test.txt'; try { FileObject::filePutContents($filename, 'content'); $this->fail('Expected exception has not been thrown'); } catch (\RuntimeException $e) { $this->assertEquals("Error writing to file {$filename}", $e->getMessage()); // A truncated file should remain on disk $this->assertFileExists($filename); $this->assertEquals('con', file_get_contents($filename)); } }
public function testSaveRemovesFileOnError() { $root = vfsStream::setup('root'); $filename = $root->url() . '/test.xml'; $document = new DomDocument(); vfsStream::setQuota(1); // File is opened, written but truncated try { $document->save($filename); $this->fail('Expected exception has not been thrown'); } catch (\RuntimeException $e) { $this->assertEquals("Error writing to file {$filename}", $e->getMessage()); $this->assertFileNotExists($filename); } }