public function save(NewPost $entry, $files) { foreach ($files as $uploadedFile) { try { $stream = fopen($uploadedFile->getRealPath(), 'rb'); if (!$stream) { $m = "Could not open file " . $uploadedFile->getRealPath(); throw new \RuntimeException($m); } $this->filesystem->writeStream($entry->getFilePath() . "." . $uploadedFile->getExtension(), $stream); } catch (FileExistsException $e) { throw new RuntimeException($e->getMessage()); } } try { // json file $this->filesystem->write($entry->getFilePath() . ".json", $entry->asJson()); } catch (FileExistsException $e) { throw new RuntimeException($e->getMessage()); } }
/** * @test */ public function it_creates_a_filepath_from_the_posts_uid() { $post = new NewPost([]); $result = $post->getFilePath(); $this->assertRegExp("/\\d{4}\\/\\d{14}_\\w{13}/", $result); }