Skip to content
Merged
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
10 changes: 8 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ on:
jobs:
tests:
runs-on: ${{ matrix.os }}

strategy:
fail-fast: true
matrix:
os: [ubuntu-latest]
php: ['8.0', 8.1, 8.2, 8.3]
laravel: [9.*, 10.*, 11.*]
php: [8.2, 8.3, 8.4]
laravel: ['10.*', '11.*', '12.*']
dependency-version: [prefer-lowest, prefer-stable]
exclude:
- laravel: 9.*
Expand All @@ -27,6 +28,10 @@ jobs:
php: '8.0'
- laravel: 11.*
php: 8.1
- laravel: 12.*
php: '8.0'
- laravel: 12.*
php: 8.1

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }}

Expand All @@ -46,5 +51,6 @@ jobs:
run: |
composer require "illuminate/console:${{ matrix.laravel }}" "illuminate/mail:${{ matrix.laravel }}" "illuminate/view:${{ matrix.laravel }}" --no-interaction --no-update
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-progress

- name: Execute tests
run: vendor/bin/pest
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
],
"homepage": "https://github.com/beyondcode/helo-laravel",
"require": {
"php": "^8.0 || ^8.1 || ^8.2",
"illuminate/console": "^8.0 || ^9.0 || ^10.0 || ^11.0",
"illuminate/mail": "^8.0 || ^9.0 || ^10.0 || ^11.0",
"illuminate/view": "^8.0 || ^9.0 || ^10.0 || ^11.0"
"php": "^8.2",
"illuminate/console": "^10.0 || ^11.0 || ^12.0",
"illuminate/mail": "^10.0 || ^11.0 || ^12.0",
"illuminate/view": "^10.0 || ^11.0 || ^12.0"
},
"require-dev": {
"orchestra/testbench": "^7.0 || ^8.0 || ^9.0",
"pestphp/pest": "1.x-dev || 2.x-dev"
"orchestra/testbench": "^8.0 || ^9.0 || ^10.0 || ^11.0 || ^12.0",
"pestphp/pest": "1.x-dev || 2.x-dev || ^3.7"
},
"minimum-stability": "dev",
"autoload": {
Expand Down
56 changes: 21 additions & 35 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,37 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheDirectory=".phpunit.cache"
executionOrder="depends,defects"
beStrictAboutCoverageMetadata="true"
beStrictAboutOutputDuringTests="true"
colors="true"
backupGlobals="false"
backupStaticProperties="false"
stopOnError="false"
stopOnFailure="false">
<testsuites>
<testsuite name="BeyondCode Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>

<source restrictDeprecations="true" restrictNotices="true" restrictWarnings="true">
<include>
<directory>src</directory>
</include>
</source>

<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>

<coverage>
<report>
<html outputDirectory="build/html-coverage" />
<text outputFile="build/coverage.txt" />
<clover outputFile="build/clover.xml" />
</report>
</coverage>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.5/phpunit.xsd" bootstrap="vendor/autoload.php" cacheDirectory=".phpunit.cache" executionOrder="depends,defects" beStrictAboutCoverageMetadata="true" beStrictAboutOutputDuringTests="true" colors="true" backupGlobals="false" backupStaticProperties="false" stopOnError="false" stopOnFailure="false">
<testsuites>
<testsuite name="BeyondCode Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<source restrictNotices="true" restrictWarnings="true" ignoreIndirectDeprecations="true">
<include>
<directory>src</directory>
</include>
</source>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
<coverage>
<report>
<html outputDirectory="build/html-coverage"/>
<text outputFile="build/coverage.txt"/>
<clover outputFile="build/clover.xml"/>
</report>
</coverage>
</phpunit>
37 changes: 37 additions & 0 deletions phpunit.xml.dist.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheDirectory=".phpunit.cache"
executionOrder="depends,defects"
beStrictAboutCoverageMetadata="true"
beStrictAboutOutputDuringTests="true"
colors="true"
backupGlobals="false"
backupStaticProperties="false"
stopOnError="false"
stopOnFailure="false">
<testsuites>
<testsuite name="BeyondCode Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>

<source restrictDeprecations="true" restrictNotices="true" restrictWarnings="true">
<include>
<directory>src</directory>
</include>
</source>

<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>

<coverage>
<report>
<html outputDirectory="build/html-coverage" />
<text outputFile="build/coverage.txt" />
<clover outputFile="build/clover.xml" />
</report>
</coverage>
</phpunit>
109 changes: 5 additions & 104 deletions src/CreatesMailers.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,116 +4,21 @@

use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Swift_Mailer;

trait CreatesMailers
{
protected function createLaravel6Mailer($app)
{
$config = $this->getConfig();

// Once we have create the mailer instance, we will set a container instance
// on the mailer. This allows us to resolve mailer classes via containers
// for maximum testability on said classes instead of passing Closures.
$mailer = new Mailer(
$app['view'],
$app['swift.mailer'],
$app['events']
);

if ($app->bound('queue')) {
$mailer->setQueue($app['queue']);
}

// Next we will set all of the global addresses on this mailer, which allows
// for easy unification of all "from" addresses as well as easy debugging
// of sent messages since they get be sent into a single email address.
foreach (['from', 'reply_to', 'to'] as $type) {
$this->setGlobalAddress($mailer, $config, $type);
}

return $mailer;
}

protected function createLaravel7Mailer($app)
{
$defaultDriver = $app['mail.manager']->getDefaultDriver();
$config = $this->getConfig($defaultDriver);

// Laravel 7 no longer bindes the swift.mailer:
$swiftMailer = new Swift_Mailer($app['mail.manager']->createTransport($config));

// Once we have create the mailer instance, we will set a container instance
// on the mailer. This allows us to resolve mailer classes via containers
// for maximum testability on said classes instead of passing Closures.
$mailer = new Laravel7Mailer(
'smtp',
$app['view'],
$swiftMailer,
$app['events']
);

if ($app->bound('queue')) {
$mailer->setQueue($app['queue']);
}

// Next we will set all of the global addresses on this mailer, which allows
// for easy unification of all "from" addresses as well as easy debugging
// of sent messages since they get be sent into a single email address.
foreach (['from', 'reply_to', 'to', 'return_path'] as $type) {
$this->setGlobalAddress($mailer, $config, $type);
}

return $mailer;
}

protected function createLaravel8Mailer($app)
protected function createGeneralLaravelMailer($app)
{
$defaultDriver = $app['mail.manager']->getDefaultDriver();
$config = $this->getConfig($defaultDriver);

$swiftMailer = new Swift_Mailer($app['mail.manager']->createTransport($config));
// We get Symfony Transport from Laravel 10+ mailer
$symfonyTransport = $app['mailer']->getSymfonyTransport();

// Once we have create the mailer instance, we will set a container instance
// on the mailer. This allows us to resolve mailer classes via containers
// for maximum testability on said classes instead of passing Closures.
$mailer = new Laravel8Mailer(
'smtp',
$app['view'],
$swiftMailer,
$app['events']
);

if ($app->bound('queue')) {
$mailer->setQueue($app['queue']);
}

// Next we will set all of the global addresses on this mailer, which allows
// for easy unification of all "from" addresses as well as easy debugging
// of sent messages since they get be sent into a single email address.
foreach (['from', 'reply_to', 'to', 'return_path'] as $type) {
$this->setGlobalAddress($mailer, $config, $type);
}

return $mailer;
}

protected function createLaravel9Mailer($app)
{
$defaultDriver = $app['mail.manager']->getDefaultDriver();
$config = $this->getConfig($defaultDriver);

// We get Symfony Transport from Laravel 9 mailer
if (version_compare(app()->version(), '10.0.0', '<')) {
$symfonyTransport = $app['mail.manager']->getSymfonyTransport();
} else {
$symfonyTransport = $app['mailer']->getSymfonyTransport();
}

// Once we have create the mailer instance, we will set a container instance
// on the mailer. This allows us to resolve mailer classes via containers
// for maximum testability on said classes instead of passing Closures.
$mailer = new Laravel9Mailer(
$mailer = new GeneralLaravelMailer(
'smtp',
$app['view'],
$symfonyTransport,
Expand Down Expand Up @@ -152,11 +57,7 @@ protected function getConfig($name = 'smtp')
*/
protected function setGlobalAddress($mailer, array $config, $type)
{
if (version_compare(app()->version(), '7.0.0', '<')) {
$address = Arr::get($config, $type);
} else {
$address = Arr::get($config, $type, $this->app['config']['mail.'.$type]);
}
$address = Arr::get($config, $type, $this->app['config']['mail.'.$type]);

if (is_array($address) && isset($address['address'])) {
$mailer->{'always'.Str::studly($type)}($address['address'], $address['name']);
Expand Down
13 changes: 12 additions & 1 deletion src/Laravel8Mailer.php → src/GeneralLaravelMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,19 @@
use Illuminate\Contracts\Mail\Factory as MailFactory;
use Illuminate\Contracts\Mail\Mailer as MailerContract;

class Laravel8Mailer extends Laravel7Mailer implements MailerContract, MailFactory
class GeneralLaravelMailer extends Mailer implements MailerContract, MailFactory
{
public $currentMailer = null;
protected $app;
protected $mailers = [];

public function mailer($name = null)
{
$this->currentMailer = $name;

return $this;
}

/**
* Set laravel application.
*
Expand Down
20 changes: 3 additions & 17 deletions src/HeloLaravelServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,30 +45,16 @@ public function register()
$this->mergeConfigFrom(__DIR__.'/../config/helo.php', 'helo');

$this->app->singleton(Mailer::class, function ($app) {
$version = $this->version($app);

if ($version < 7) {
return $this->createLaravel6Mailer($app);
}

if ($version < 8) {
return $this->createLaravel7Mailer($app);
}

if ($version < 9) {
return $this->createLaravel8Mailer($app);
}

return $this->createLaravel9Mailer($app);
return $this->createGeneralLaravelMailer($app);
});
}

protected function bootMailable()
{
$managerInstance = app()->make(MailManager::class, ['app' => app()]);
$instance = app()->make(Mailer::class);

Mail::swap($instance);

Mail::swap($managerInstance);
$this->app->instance(MailerContract::class, $instance);
}

Expand Down
18 changes: 0 additions & 18 deletions src/Laravel7Mailer.php

This file was deleted.

10 changes: 0 additions & 10 deletions src/Laravel9Mailer.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/MailManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class MailManager extends LaravelMailManager implements FactoryContract
public function mailer($name = null)
{
if (!$name) {
return $this->createLaravel9Mailer($this->app);
return $this->createGeneralLaravelMailer($this->app);
}

return $this->mailers[$name] = $this->get($name);
Expand Down
7 changes: 1 addition & 6 deletions tests/HeloTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace BeyondCode\HeloLaravel\Tests;

use BeyondCode\HeloLaravel\Laravel7Mailer;
use BeyondCode\HeloLaravel\Mailer;
use BeyondCode\HeloLaravel\TestMail;
use BeyondCode\HeloLaravel\TestMailCommand;
Expand All @@ -29,9 +28,5 @@
test('the correct mailer is binded', function () {
$mailer = app(Mailer::class);

if (version_compare(app()->version(), '7.0.0', '<')) {
$this->assertTrue($mailer instanceof Mailer);
} else {
$this->assertTrue($mailer instanceof Laravel7Mailer);
}
$this->assertTrue($mailer instanceof Mailer);
});