function testCreationReturnsFalseWhenItFailsToCreateFile() { $filename = $this->createDirPath($this->tempdir, 'foo.txt'); File::create($filename, 'boo!'); $this->setExpectedException('Asar\\FileHelper\\Exception\\FileAlreadyExists'); $this->helper->create($filename, "Foo!"); }
function create($filename, $contents) { try { return File::create($filename)->write($contents)->save(); } catch (\Asar\File\Exception\FileAlreadyExists $e) { throw new FileAlreadyExists("The file '{$filename}' already exists."); } }
function testSettingContentUsingArrayAsArgument() { $content = array('AA', 'BB', 'CC', 'DD'); $testFileName = $this->getTempFileName('temp/XXXXXXtest.txt'); mkdir($this->getTempFileName('temp')); $file = File::create($testFileName)->write($content)->save(); $this->assertEquals("AA\nBB\nCC\nDD", $file->getContent()); }