From 7f632e87492fd30b2ecacde3a3e8b0c8a0560816 Mon Sep 17 00:00:00 2001 From: Roman Schmid Date: Mon, 11 Oct 2021 11:58:47 +0200 Subject: [PATCH] Update for SilverStripe 4.9 / Swiftmailer 6 --- .travis.yml | 14 ++++++-------- README.md | 2 +- composer.json | 8 ++++---- src/EmogrifierPlugin.php | 10 +++------- tests/EmogrifierPluginTest.php | 35 ++++++---------------------------- 5 files changed, 20 insertions(+), 49 deletions(-) diff --git a/.travis.yml b/.travis.yml index 065235d..a8752fa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,5 @@ language: php sudo: false -dist: trusty env: global: @@ -9,21 +8,21 @@ env: matrix: include: - - php: 5.6 + - php: 7.2 env: - - PHP5=1 - PHPCS_TEST=1 - PHPUNIT_TEST=1 - - php: 7.0 - env: - - PHPUNIT_TEST=1 - php: 7.4 env: - PHPUNIT_COVERAGE_TEST=1 + - php: 8.0 + env: + - PHPUNIT_TEST=1 + before_script: # Init PHP - - composer self-update || true + - composer self-update --2 || true - phpenv rehash - phpenv config-rm xdebug.ini || true @@ -32,7 +31,6 @@ before_script: - composer update script: - - if [[ $PHP5 ]]; then composer require silverstripe/assets 1.4.8; fi - if [[ $PHPUNIT_TEST ]]; then vendor/bin/phpunit; fi - if [[ $PHPUNIT_COVERAGE_TEST ]]; then phpdbg -qrr vendor/bin/phpunit --coverage-clover=coverage.xml; fi - if [[ $PHPCS_TEST ]]; then composer run-script lint; fi diff --git a/README.md b/README.md index 3de3e32..0caed42 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Easily integrate Emogrifier into SilverStripe and send Emails with inlined CSS a ## Installation and Requirements - Requires the [EmogrifierPlugin](https://github.com/bummzack/swiftmailer-emogrifyplugin) and its dependencies. - - SilverStripe 4.1+ + - SilverStripe 4.9+ Install via composer: diff --git a/composer.json b/composer.json index 142d66a..ba2c2a2 100644 --- a/composer.json +++ b/composer.json @@ -9,9 +9,9 @@ "emogrifier" ], "require": { - "silverstripe/framework": "^4.1", - "silverstripe/assets": "^1.1", - "bummzack/swiftmailer-emogrifyplugin" : "^0.2" + "php": "^7.2 || ^8.0", + "silverstripe/framework": "^4.9", + "bummzack/swiftmailer-emogrifyplugin" : "^1.0" }, "require-dev": { "phpunit/phpunit": "^5.7", @@ -19,7 +19,7 @@ }, "extra": { "branch-alias": { - "dev-master": "0.x-dev" + "dev-master": "1.x-dev" } }, "autoload": { diff --git a/src/EmogrifierPlugin.php b/src/EmogrifierPlugin.php index 652280a..a4376db 100644 --- a/src/EmogrifierPlugin.php +++ b/src/EmogrifierPlugin.php @@ -2,7 +2,6 @@ namespace Bummzack\SilverStripeEmogrify; -use Pelago\Emogrifier; use SilverStripe\Assets\File; use SilverStripe\Core\Config\Configurable; use SilverStripe\Core\Path; @@ -22,18 +21,15 @@ class EmogrifierPlugin extends \Bummzack\SwiftMailer\EmogrifyPlugin\EmogrifierPl * Can be set via config YAML. * * @config - * @var string + * @var string|null */ private static $css_file = null; /** * EmogrifierPlugin constructor. - * @param Emogrifier|null $emogrifier */ - public function __construct(Emogrifier $emogrifier = null) + public function __construct() { - parent::__construct($emogrifier); - if ($file = $this->config()->css_file) { $this->loadCssFromFile($file); } @@ -61,7 +57,7 @@ public function loadCssFromFile($file) throw new \InvalidArgumentException('File "' . $path . '" does not have .css extension.'); } - $this->getEmogrifier()->setCss(file_get_contents($path)); + $this->setCss(file_get_contents($path)); return $this; } diff --git a/tests/EmogrifierPluginTest.php b/tests/EmogrifierPluginTest.php index fe4eab2..a9cfa1c 100644 --- a/tests/EmogrifierPluginTest.php +++ b/tests/EmogrifierPluginTest.php @@ -3,13 +3,14 @@ namespace Bummzack\SilverStripeEmogrify\Tests; use Bummzack\SilverStripeEmogrify\EmogrifierPlugin; -use Pelago\Emogrifier; use SilverStripe\Core\Config\Config; use SilverStripe\Core\Path; use SilverStripe\Dev\SapphireTest; class EmogrifierPluginTest extends SapphireTest { + protected $usesDatabase = false; + public function setUp() { parent::setUp(); @@ -22,15 +23,17 @@ public function testLoadCssFromConfig() $file = realpath(__DIR__) . DIRECTORY_SEPARATOR . 'EmogrifierPluginTest.css'; Config::modify()->set(EmogrifierPlugin::class, 'css_file', $file); - new EmogrifierPlugin($this->createMockEmogrifier()); + $plugin = new EmogrifierPlugin(); + $this->assertEquals($plugin->getCss(), file_get_contents($file)); } public function testLoadCssFromFile() { $file = realpath(__DIR__) . DIRECTORY_SEPARATOR . 'EmogrifierPluginTest.css'; - $plugin = new EmogrifierPlugin($this->createMockEmogrifier()); + $plugin = new EmogrifierPlugin(); $plugin->loadCssFromFile($file); + $this->assertEquals($plugin->getCss(), file_get_contents($file)); $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('File "' . __FILE__ . '" does not have .css extension.'); @@ -44,30 +47,4 @@ public function testLoadNonExistantCssFile() $plugin = new EmogrifierPlugin(); $plugin->loadCssFromFile('testDummy.css'); } - - /** - * Create a mock emogrifier instance to ensure the CSS that is being set will match the code from the test file. - * @return \PHPUnit_Framework_MockObject_MockObject - */ - private function createMockEmogrifier() - { - $css = <<getMockBuilder(Emogrifier::class) - ->disableOriginalConstructor() - ->getMock(); - - $emogrifier->expects($this->once()) - ->method('setCss') - ->with( - $this->equalTo($css) - ); - - return $emogrifier; - } }