Skip to content
Open
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![Latest Stable Version](https://poser.pugx.org/notfloran/mjml-bundle/v/stable.svg)](https://packagist.org/packages/notfloran/mjml-bundle)
[![Latest Unstable Version](https://poser.pugx.org/notfloran/mjml-bundle/v/unstable.svg)](https://packagist.org/packages/notfloran/mjml-bundle)

Bundle to use [MJML](https://mjml.io/) 3 and 4 with Symfony >= 3.
Bundle to use [MJML](https://mjml.io/) 4 with Symfony >= 3.

## Installation

Expand Down
5 changes: 0 additions & 5 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ public function getConfigTreeBuilder(): TreeBuilder
->booleanNode('minify')
->defaultFalse()
->end()
->integerNode('mjml_version')
->min(3)->max(4)
->defaultNull()
->info('Mjml version')
->end()
->end()
->end()
->end()
Expand Down
46 changes: 3 additions & 43 deletions src/Renderer/BinaryRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@

final class BinaryRenderer implements RendererInterface
{
private const VERSION_4 = 4;
private const VERSION_BEFORE_4 = 3;

/**
* @var string
*/
Expand All @@ -24,71 +21,34 @@ final class BinaryRenderer implements RendererInterface
*/
private $validationLevel;

/**
* @var int|null
*/
private $mjmlVersion;

/**
* @var string|null
*/
private $node;

public function __construct(string $bin, bool $minify, string $validationLevel, ?string $node = null, ?int $mjmlVersion = null)
public function __construct(string $bin, bool $minify, string $validationLevel, ?string $node = null)
{
$this->bin = $bin;
$this->minify = $minify;
$this->validationLevel = $validationLevel;
$this->node = $node;
$this->mjmlVersion = $mjmlVersion;
}

public function getMjmlVersion(): int
{
if (null === $this->mjmlVersion) {
$command = [];
if ($this->node) {
$command[] = $this->node;
}

array_push($command, $this->bin, '--version');

$process = new Process($command);
$process->mustRun();

$this->mjmlVersion = self::VERSION_4;
if (false === strpos($process->getOutput(), 'mjml-core: 4.')) {
$this->mjmlVersion = self::VERSION_BEFORE_4;
}
}

return $this->mjmlVersion;
}

public function render(string $mjmlContent): string
{
$version = $this->getMjmlVersion();

$command = [];
if ($this->node) {
$command[] = $this->node;
}

array_push($command, $this->bin, '-i', '-s');

$strictArgument = '-l';
if (self::VERSION_4 === $version) {
$strictArgument = '--config.validationLevel';
}
$strictArgument = '--config.validationLevel';

array_push($command, $strictArgument, $this->validationLevel);

if (true === $this->minify) {
if (self::VERSION_4 === $version) {
array_push($command, '--config.minify', 'true');
} else {
$command[] = '-m';
}
array_push($command, '--config.minify', 'true');
}

// Create process
Expand Down
33 changes: 0 additions & 33 deletions tests/Configuration/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,37 +99,4 @@ public function testInvalidValidationLevelConfiguration()

$this->assertConfigurationIsInvalid($config, 'Validation level is invalid');
}

public function testMjmlVersionConfiguration()
{
$config = [
[
'renderer' => 'binary',
'options' => [
'binary' => 'mjml',
'mjml_version' => 4,
],
],
];

$this->assertConfigurationIsValid($config);
}

public function testInvalidMjmlVersionConfiguration()
{
$config = [
[
'renderer' => 'binary',
'options' => [
'binary' => 'mjml',
'mjml_version' => 2,
],
],
];

$this->assertConfigurationIsInvalid(
$config,
'The value 2 is too small for path "mjml.options.mjml_version". Should be greater than or equal to 3'
);
}
}
18 changes: 0 additions & 18 deletions tests/Renderer/BinaryRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,6 @@ public function testUseNode()
$this->assertStringContains('html', $html);
}

/**
* @dataProvider mjmlVersionDataProvider
*/
public function testUseMjmlVersion(int $mjmlVersion)
{
$renderer = new BinaryRenderer($this->getMjmlBinary(), false, 'strict', null, $mjmlVersion);
$html = $renderer->render(file_get_contents(__DIR__.'/../fixtures/basic.mjml'));

$this->assertStringContains('html', $html);
$this->assertStringContains('Hello Floran from MJML and Symfony', $html);
}

public function mjmlVersionDataProvider()
{
yield ['old version' => 3];
yield ['actual version' => 4];
}

/**
* Allow to use PHPUnit < and > 9.
*
Expand Down