*/ private array $compiledDocuments = []; /** * @param class-string $documentClass * @param callable(Document): bool $check */ public function assertCompiled(string $documentClass, callable $check): void { $compilations = $this->getCompilations($documentClass); Assert::assertFalse( $compilations->isEmpty(), 'The TeX Document "'.$documentClass.'" has not been compiled at all.' ); Assert::assertFalse( $compilations->isEmpty(), 'The TeX Document "'.$documentClass.'" has not been compiled.' ); $validDocuments = $compilations->filter(fn ($compilation) => $check($compilation)); Assert::assertNotEmpty($validDocuments, 'Failed that TeX Document "'.$documentClass.'" has been compiled with given check.'); } /** * @param class-string $documentClass * * @return Collection */ protected function getCompilations(string $documentClass): Collection { return collect($this->compiledDocuments)->filter(fn ($rendered) => get_class($rendered) === $documentClass); } public function compile(Document $document): self { $path = '/tmp/'.$document->filename().'.pdf'; $file = UploadedFile::fake()->create($document->filename().'.pdf', 100, 'application/pdf'); file_put_contents($path, $file->get()); $this->file = new File($path, true); $this->compiledDocuments[] = $document; return $this; } }