Specify output for compilerException

This commit is contained in:
Philipp Lang 2022-10-31 13:52:41 +01:00
parent fb9d7a660c
commit ae4d9f74ef
3 changed files with 22 additions and 1 deletions

View File

@ -25,7 +25,9 @@ abstract class BaseCompiler implements Responsable
exec($this->command($document), $output, $returnVar);
$this->refreshFile();
throw_unless($this->file->isFile(), CompilerException::class, 'Compilation failed.');
if (!$this->file->isFile()) {
throw (new CompilerException('Compilation failed.'))->setOutput($output);
}
return $this;
}

View File

@ -6,4 +6,12 @@ use Exception;
class CompilerException extends Exception
{
public string $output;
public function setOutput(array $output): self
{
$this->output = implode("\n", $output);
return $this;
}
}

View File

@ -2,6 +2,8 @@
namespace Zoomyboy\Tex;
use PHPUnit\Framework\Assert;
abstract class Document
{
abstract public function basename(): string;
@ -19,6 +21,15 @@ abstract class Document
->render();
}
public function assertHasContent(string $content): void
{
Assert::assertStringContainsString(
$content,
$this->renderBody(),
"Failed asserting that Content contains {$content}"
);
}
public function hasContent(string $content): bool
{
return str_contains($this->renderBody(), $content);