Skip to content

Commit

Permalink
Merge pull request #6 from Baspa/main
Browse files Browse the repository at this point in the history
Check for deprecation warning
  • Loading branch information
freekmurze authored Oct 9, 2023
2 parents 37b7b3f + d94c5bf commit 61f1b05
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
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

0 comments on commit 61f1b05

Please sign in to comment.