Skip to content

Commit

Permalink
Update to PHP8 and add support for mailgun-php ^3.0 (#88)
Browse files Browse the repository at this point in the history
* Experiments

* Make the logger conditional

* Update dev dependencies

* Add php7.3 version, fix unit tests

* Migrate XML configuration

* Update symfony dependencies
  • Loading branch information
elblasto authored Sep 13, 2021
1 parent c6520f2 commit b77b8e4
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 52 deletions.
5 changes: 2 additions & 3 deletions DependencyInjection/cspooSwiftmailerMailgunExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace cspoo\Swiftmailer\MailgunBundle\DependencyInjection;

use Mailgun\HttpClientConfigurator;
use Mailgun\HttpClient\HttpClientConfigurator;
use Mailgun\Mailgun;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand Down Expand Up @@ -63,8 +63,7 @@ private function registerMailgunService(ContainerBuilder $container, array $conf
}

$mailgunDef = new Definition(Mailgun::class);
$mailgunDef->setFactory([Mailgun::class, 'configure'])
->addArgument($configuratorDef);
$mailgunDef->addArgument($configuratorDef);

$container->setDefinition('mailgun.library', $mailgunDef);
}
Expand Down
8 changes: 5 additions & 3 deletions Service/MailgunTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function __construct(
\Swift_Events_EventDispatcher $eventDispatcher,
Mailgun $mailgun,
$domain,
LoggerInterface $logger
LoggerInterface $logger = null
) {
$this->eventDispatcher = $eventDispatcher;
$this->domain = $domain;
Expand Down Expand Up @@ -97,7 +97,7 @@ public function stop()
* @param string[] $failedRecipients An array of failures by-reference
*
* @throws \Swift_TransportException
*
*
* @return int number of mails sent
*/
public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = null)
Expand Down Expand Up @@ -133,7 +133,9 @@ public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = nul
'mailgun_http_response_body' => $e->getResponseBody()
];
}
$this->logger->error($e->getMessage(), $context);
if($this->logger) {
$this->logger->error($e->getMessage(), $context);
}
}

if ($evt) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
class cspooSwiftmailerMailgunExtensionTest extends AbstractExtensionTestCase
{
protected function getContainerExtensions()
protected function getContainerExtensions(): array
{
return array(
new cspooSwiftmailerMailgunExtension()
Expand All @@ -21,7 +21,7 @@ protected function getContainerExtensions()
/**
* @inheritDoc
*/
protected function getMinimalConfiguration()
protected function getMinimalConfiguration(): array
{
return array('key' => 'foo', 'domain' => 'bar', 'endpoint' => 'baz');
}
Expand Down Expand Up @@ -54,4 +54,4 @@ public function after_loading_the_correct_parameter_has_been_set()

$this->assertContainerBuilderHasServiceDefinitionWithArgument('mailgun.swift_transport.transport', 0, 'mailgun.swift_transport.eventdispatcher');
}
}
}
9 changes: 7 additions & 2 deletions Tests/Service/MailgunTransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function testSendMessageOk()
public function testSendMessageWithException()
{
$dispatcher = $this->getMockBuilder('Swift_Events_EventDispatcher')->getMock();
$mailgun = $this->getMockBuilder('Mailgun\Mailgun')->getMock();
$mailgun = $this->getMockBuilder('Mailgun\Mailgun')->disableOriginalConstructor()->getMock();
$logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
$logger->expects($this->once())
->method('error');
Expand Down Expand Up @@ -161,7 +161,7 @@ public function testSendMessageWithException()
public function testSendMessageWithHttpClientException()
{
$dispatcher = $this->getMockBuilder('Swift_Events_EventDispatcher')->getMock();
$mailgun = $this->getMockBuilder('Mailgun\Mailgun')->getMock();
$mailgun = $this->getMockBuilder('Mailgun\Mailgun')->disableOriginalConstructor()->getMock();
$logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();

$logger->expects($this->once())
Expand Down Expand Up @@ -196,6 +196,10 @@ public function testSendMessageWithHttpClientException()
->method('getReasonPhrase')
->willReturn('UNAUTHORIZED');

$response->expects($this->any())
->method('getHeaderLine')
->willReturn('');

$messageApi = $this->getMockBuilder('Mailgun\Api\Message')
->disableOriginalConstructor()
->getMock();
Expand Down Expand Up @@ -243,6 +247,7 @@ private function getTransport()
->willReturn(SendResponse::create(['id'=>'123', 'message'=>'OK']));

$mailgun = $this->getMockBuilder('Mailgun\Mailgun')
->disableOriginalConstructor()
->getMock();

$mailgun->expects($this->any())
Expand Down
20 changes: 10 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@
],
"minimum-stability" : "stable",
"require": {
"php": "^7.0",
"php": "^7.3 || ^8.0",
"swiftmailer/swiftmailer": "^6.0",
"mailgun/mailgun-php": "^2.3",
"symfony/config": "^3.3 || ^4.0",
"symfony/dependency-injection": "^3.3 || ^4.0",
"symfony/http-kernel": "^3.3 || ^4.0",
"mailgun/mailgun-php": "^3.0",
"symfony/config": "^3.3 || ^4.0 || ^5.0",
"symfony/dependency-injection": "^3.3 || ^4.0 || ^5.0",
"symfony/http-kernel": "^3.3 || ^4.0 || ^5.0",
"psr/log": "^1.1"
},
"require-dev": {
"symfony/phpunit-bridge": "^4.0",
"matthiasnoback/symfony-dependency-injection-test": "^2.3.1 || ^3.0",
"symfony/phpunit-bridge": "^4.0 || ^5.0",
"matthiasnoback/symfony-dependency-injection-test": "^2.3.1 || ^4.0",
"nyholm/symfony-bundle-test": "^1.4",
"symfony/swiftmailer-bundle": "^2.5.1 || ^3.2",
"php-http/curl-client": "^1.7",
"zendframework/zend-diactoros": "^1.7",
"symfony/framework-bundle": "^3.3 || ^4.0",
"php-http/curl-client": "^2.0",
"laminas/laminas-diactoros": "^2.0",
"symfony/framework-bundle": "^3.3 || ^4.0 ||^5.0",
"doctrine/annotations": "^1.3"
},
"suggest": {
Expand Down
49 changes: 18 additions & 31 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,33 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="./vendor/autoload.php"
>

<testsuites>
<testsuite name="All Tests">
<directory>./Tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory suffix=".php">./</directory>
<exclude>
<directory>vendor</directory>
<directory>Tests</directory>
</exclude>
</whitelist>
</filter>

<listeners>
<listener class="Symfony\Bridge\PhpUnit\CoverageListener"/>
</listeners>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" colors="false" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" bootstrap="./vendor/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">./</directory>
</include>
<exclude>
<directory>vendor</directory>
<directory>Tests</directory>
</exclude>
</coverage>
<testsuites>
<testsuite name="All Tests">
<directory>./Tests</directory>
</testsuite>
</testsuites>
<listeners>
<listener class="Symfony\Bridge\PhpUnit\CoverageListener"/>
</listeners>
</phpunit>
33 changes: 33 additions & 0 deletions phpunit.xml.dist.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="./vendor/autoload.php"
>

<testsuites>
<testsuite name="All Tests">
<directory>./Tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory suffix=".php">./</directory>
<exclude>
<directory>vendor</directory>
<directory>Tests</directory>
</exclude>
</whitelist>
</filter>

<listeners>
<listener class="Symfony\Bridge\PhpUnit\CoverageListener"/>
</listeners>
</phpunit>

0 comments on commit b77b8e4

Please sign in to comment.