/** * By default opens existing files only, but can be forced to create new ones. * * @param string $filename * @param bool $force * * @return File * * @throws \Symfony\Component\Filesystem\Exception\FileNotFoundException If the file hasn't be found. * * @api */ public function open($filename, $force = false) { if (!$this->filesystem->exists($filename) && $force) { return $this->filesystem->create($filename); } return $this->filesystem->open($filename); }
function it_cannot_open_new_files(Filesystem $filesystem, File $file) { $exception = new \Gnugat\Redaktilo\Exception\FileNotFoundException(self::FILENAME); $filesystem->exists(self::FILENAME)->willReturn(false); $filesystem->open(self::FILENAME)->willThrow($exception); $this->shouldThrow($exception)->duringOpen(self::FILENAME); }