Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better exceptions for failed commands in BinaryRenderer #37

Merged
merged 1 commit into from
Jun 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 2 additions & 22 deletions src/Renderer/BinaryRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,7 @@ private function getMjmlVersion() : int
$this->bin,
'-V',
]);
$process->run();

if (true !== $process->isSuccessful()) {
throw new \InvalidArgumentException(sprintf(
"Couldn't find the MJML binary"
));
}
$process->mustRun();

$this->mjmlVersion = self::VERSION_4;
if (strpos($process->getOutput(), 'mjml-core: 4.') === false) {
Expand Down Expand Up @@ -83,21 +77,7 @@ public function render(string $mjmlContent) : string
// Create process
$process = new Process($arguments);
$process->setInput($mjmlContent);
$process->run();

// Executes after the command finishes
if (true !== $process->isSuccessful()) {
throw new \RuntimeException(sprintf(
'The exit status code \'%s\' says something went wrong:' . "\n"
. 'stderr: "%s"' . "\n"
. 'stdout: "%s"' . "\n"
. 'command: %s.',
$process->getStatus(),
$process->getErrorOutput(),
$process->getOutput(),
$process->getCommandLine()
));
}
$process->mustRun();

return $process->getOutput();
}
Expand Down
7 changes: 7 additions & 0 deletions tests/Renderer/BinaryRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,11 @@ public function testInvalidRender()
$renderer->render(file_get_contents(__DIR__.'/../fixtures/invalid.mjml'));
}

public function testBinaryNotFound()
{
$this->expectException(\RuntimeException::class);

$renderer = new BinaryRenderer('mjml-not-found', false);
$renderer->render(file_get_contents(__DIR__.'/../fixtures/basic.mjml'));
}
}