function it_should_create_pdf_files_from_a_given_gist(Gist $gist) { $gist->files()->willReturn([['filename' => 'foo', 'content' => '<h1>bar</h1>']]); $this->beConstructedFromGist($gist); $this->shouldHaveType(Pdf::class); expect(file_exists('foo.pdf'))->toBe(true); }
public function requestFilesFromGist(Gist $gist) { $client = new Client("https://api.github.com"); $response = $client->get("/gists/{$gist->getId()}")->send(); if (!$response->isSuccessful()) { throw new \Exception($response->getStatusCode() . ' ' . $response->getReasonPhrase()); } $gist = json_decode($response->getBody(), true); return $gist['files']; }
/** * @Then /^I should create and download a PDF file$/ */ public function iShouldCreateAndDownloadAPDFFile() { foreach ($this->gist->files() as $file) { $filename = rtrim($file['filename'], '.pdf') . '.pdf'; if (!file_exists($filename)) { throw new Exception("File {$filename} was not found in " . getcwd()); } // verified file exists, now clean up the file unlink($filename); } }
function it_can_request_files_from_a_gist(Gist $gist) { $gist->getId()->willReturn('bb7628ad34c699392f9c'); $this->requestFilesFromGist($gist)->shouldBeArray(); }
private function __construct(Gist $gist) { foreach ($gist->files() as $file) { $this->createPdf($file['filename'], $file['content']); } }