From 473901ee2fde1c1140186648373c552eb7b71d70 Mon Sep 17 00:00:00 2001 From: Sergey Shevchenko Date: Tue, 2 Aug 2022 22:49:39 +1200 Subject: [PATCH] feat: PHP 8.0 compatibility * use phpunit/phpunit ^9.5 * use pelago/emogrifier ^6.0 * added .gitignore to ignore tests-related files * changed phpunit.xml.dist into new format * removed pelago/emogrifier v2 support --- .gitignore | 5 +++++ composer.json | 7 ++++--- phpunit.xml.dist | 15 +++++++-------- src/EmailUtils.php | 38 ++++++++++++++------------------------ tests/EmailUtilsTest.php | 4 +--- tests/MailgunTest.php | 4 ++-- 6 files changed, 33 insertions(+), 40 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3b2f55f --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +/vendor +.phpunit.result.cache +/resources +/app +/assets diff --git a/composer.json b/composer.json index 4525cf7..f88d462 100644 --- a/composer.json +++ b/composer.json @@ -14,16 +14,17 @@ "email": "thomas@lekoala.be" }], "require": { - "php": ">=7", + "php": ">=8", "silverstripe/framework": "^4.0", + "silverstripe/cms": "^4.0", "symbiote/silverstripe-gridfieldextensions": "^3.2", - "pelago/emogrifier": "^2.0 || ^3.0", + "pelago/emogrifier": "^6.0", "mailgun/mailgun-php": "^3.0", "kriswallsmith/buzz": "^1.0", "nyholm/psr7": "^1.2" }, "require-dev": { - "phpunit/phpunit": "^5.7", + "phpunit/phpunit": "^9.5", "squizlabs/php_codesniffer": "^3.0" }, "extra": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 102e5ed..afd1ace 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -2,13 +2,12 @@ tests/ - - - + + src/ - - tests/ - - - + + + tests/ + + diff --git a/src/EmailUtils.php b/src/EmailUtils.php index 0eeaedd..56a898a 100644 --- a/src/EmailUtils.php +++ b/src/EmailUtils.php @@ -20,35 +20,25 @@ class EmailUtils */ public static function inline_styles($html) { - if (class_exists(CssInliner::class)) { - // V3 - $cssInliner = CssInliner::fromHtml($html)->inlineCss(''); - $domDocument = $cssInliner->getDomDocument(); + $cssInliner = CssInliner::fromHtml($html)->inlineCss(''); + $domDocument = $cssInliner->getDomDocument(); - // potentially, we could also remove classes - // HtmlPruner::fromDomDocument($domDocument)->removeElementsWithDisplayNone() - // ->removeRedundantClassesAfterCssInlined($cssInliner); + // potentially, we could also remove classes + // HtmlPruner::fromDomDocument($domDocument)->removeElementsWithDisplayNone() + // ->removeRedundantClassesAfterCssInlined($cssInliner); - // disableInvisibleNodeRemoval - $doc = HtmlPruner::fromDomDocument($domDocument); - if (method_exists($doc, 'removeInvisibleNodes')) { - $doc->removeInvisibleNodes(); - } else { - $doc->removeElementsWithDisplayNone(); - } - - // enableCssToHtmlMapping - $html = CssToAttributeConverter::fromDomDocument($domDocument) - ->convertCssToVisualAttributes()->render(); + // disableInvisibleNodeRemoval + $doc = HtmlPruner::fromDomDocument($domDocument); + if (method_exists($doc, 'removeInvisibleNodes')) { + $doc->removeInvisibleNodes(); } else { - // V2 - $emogrifier = new Emogrifier(); - $emogrifier->disableInvisibleNodeRemoval(); - $emogrifier->enableCssToHtmlMapping(); - $emogrifier->setHtml($html); - $html = $emogrifier->emogrify(); + $doc->removeElementsWithDisplayNone(); } + // enableCssToHtmlMapping + $html = CssToAttributeConverter::fromDomDocument($domDocument) + ->convertCssToVisualAttributes()->render(); + return $html; } diff --git a/tests/EmailUtilsTest.php b/tests/EmailUtilsTest.php index 421862b..2f8a971 100644 --- a/tests/EmailUtilsTest.php +++ b/tests/EmailUtilsTest.php @@ -3,8 +3,6 @@ namespace LeKoala\Mailgun\Test; use SilverStripe\Dev\SapphireTest; -use SilverStripe\Control\Email\Email; -use SilverStripe\Core\Injector\Injector; use LeKoala\Mailgun\EmailUtils; /** @@ -56,7 +54,7 @@ public function testGetEmail() public function testInlineStyles() { - if (!class_exists(\Pelago\Emogrifier::class)) { + if (!class_exists(\Pelago\Emogrifier\CssInliner::class)) { return $this->markTestIncomplete('Install pelago\emogrifier to run this test'); } diff --git a/tests/MailgunTest.php b/tests/MailgunTest.php index f10112a..0a88845 100644 --- a/tests/MailgunTest.php +++ b/tests/MailgunTest.php @@ -25,7 +25,7 @@ class MailgunTest extends SapphireTest */ protected $testMailer; - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -41,7 +41,7 @@ protected function setUp() MailgunHelper::registerTransport(); } - protected function tearDown() + protected function tearDown(): void { parent::tearDown();