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

Check for deprecation warning #6

Merged
merged 2 commits into from
Oct 9, 2023
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
14 changes: 14 additions & 0 deletions src/Mjml.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ public function convert(string $mjml, array $options = []): MjmlResult
? $this->getSideCarResult($arguments)
: $this->getLocalResult($arguments);


$resultString = $this->checkForDeprecationWarning($resultString);

$resultProperties = json_decode($resultString, true);

if (array_key_exists('mjmlError', $resultProperties)) {
Expand All @@ -147,6 +150,17 @@ public function convert(string $mjml, array $options = []): MjmlResult
return new MjmlResult($resultProperties);
}

protected function checkForDeprecationWarning(string $result): string
{
$deprecationWarning = 'MJML v3 syntax detected, migrating to MJML v4 syntax. Use mjml -m to get the migrated MJML.';

if (str_contains($result, $deprecationWarning)) {
$result = str_replace($deprecationWarning, '', $result);
}

return $result;
}

protected function getCommand(array $arguments): array
{
return [
Expand Down
8 changes: 8 additions & 0 deletions tests/MjmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@
Mjml::new()->sidecar()->toHtml(mjmlSnippet());
})->throws(SidecarPackageUnavailable::class);

it('can determine if the given mjml can be converted when the mjml is deprecated', function (string $mjml, bool $expectedResult) {
expect(Mjml::new()->canConvert($mjml))->toBe($expectedResult);
})->with([
['<mjml><mj-body></mj-body></mjml>', true],
['<mjml><mj-body><mj-container></mj-container></mj-body></mjml>', false], // deprecated mjml
['<mjml><mj-body><mj-wrapper></mj-wrapper></mj-body></mjml>', true],
]);

function mjmlSnippet(): string
{
return <<<'MJML'
Expand Down