Skip to content

Commit

Permalink
Merge pull request #12 from gurucomkz/upgrade-to-php80
Browse files Browse the repository at this point in the history
feat: PHP 8.0 compatibility
  • Loading branch information
lekoala authored Aug 2, 2022
2 parents 904f632 + 473901e commit efbd7b3
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 40 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/vendor
.phpunit.result.cache
/resources
/app
/assets
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@
"email": "[email protected]"
}],
"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": {
Expand Down
15 changes: 7 additions & 8 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
<testsuite name="travistestmodule">
<directory>tests/</directory>
</testsuite>

<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<coverage includeUncoveredFiles="true">
<include>
<directory suffix=".php">src/</directory>
<exclude>
<directory suffix=".php">tests/</directory>
</exclude>
</whitelist>
</filter>
</include>
<exclude>
<directory suffix=".php">tests/</directory>
</exclude>
</coverage>
</phpunit>
38 changes: 14 additions & 24 deletions src/EmailUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 1 addition & 3 deletions tests/EmailUtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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');
}

Expand Down
4 changes: 2 additions & 2 deletions tests/MailgunTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class MailgunTest extends SapphireTest
*/
protected $testMailer;

protected function setUp()
protected function setUp(): void
{
parent::setUp();

Expand All @@ -41,7 +41,7 @@ protected function setUp()
MailgunHelper::registerTransport();
}

protected function tearDown()
protected function tearDown(): void
{
parent::tearDown();

Expand Down

0 comments on commit efbd7b3

Please sign in to comment.