Skip to content

Commit 7fd2bb6

Browse files
authored
Merge pull request #58 from beyondcode/dev
2.0.0
2 parents 34e8d9c + 71426d9 commit 7fd2bb6

11 files changed

+94
-200
lines changed

.github/workflows/test.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ on:
77
jobs:
88
tests:
99
runs-on: ${{ matrix.os }}
10+
1011
strategy:
1112
fail-fast: true
1213
matrix:
1314
os: [ubuntu-latest]
14-
php: ['8.0', 8.1, 8.2, 8.3]
15-
laravel: [9.*, 10.*, 11.*]
15+
php: [8.2, 8.3, 8.4]
16+
laravel: ['10.*', '11.*', '12.*']
1617
dependency-version: [prefer-lowest, prefer-stable]
1718
exclude:
1819
- laravel: 9.*
@@ -27,6 +28,10 @@ jobs:
2728
php: '8.0'
2829
- laravel: 11.*
2930
php: 8.1
31+
- laravel: 12.*
32+
php: '8.0'
33+
- laravel: 12.*
34+
php: 8.1
3035

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

@@ -46,5 +51,6 @@ jobs:
4651
run: |
4752
composer require "illuminate/console:${{ matrix.laravel }}" "illuminate/mail:${{ matrix.laravel }}" "illuminate/view:${{ matrix.laravel }}" --no-interaction --no-update
4853
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-progress
54+
4955
- name: Execute tests
5056
run: vendor/bin/pest

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
],
1717
"homepage": "https://github.com/beyondcode/helo-laravel",
1818
"require": {
19-
"php": "^8.0 || ^8.1 || ^8.2",
20-
"illuminate/console": "^8.0 || ^9.0 || ^10.0 || ^11.0",
21-
"illuminate/mail": "^8.0 || ^9.0 || ^10.0 || ^11.0",
22-
"illuminate/view": "^8.0 || ^9.0 || ^10.0 || ^11.0"
19+
"php": "^8.2",
20+
"illuminate/console": "^10.0 || ^11.0 || ^12.0",
21+
"illuminate/mail": "^10.0 || ^11.0 || ^12.0",
22+
"illuminate/view": "^10.0 || ^11.0 || ^12.0"
2323
},
2424
"require-dev": {
25-
"orchestra/testbench": "^7.0 || ^8.0 || ^9.0",
26-
"pestphp/pest": "1.x-dev || 2.x-dev"
25+
"orchestra/testbench": "^8.0 || ^9.0 || ^10.0 || ^11.0 || ^12.0",
26+
"pestphp/pest": "1.x-dev || 2.x-dev || ^3.7"
2727
},
2828
"minimum-stability": "dev",
2929
"autoload": {

phpunit.xml.dist

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,23 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
4-
bootstrap="vendor/autoload.php"
5-
cacheDirectory=".phpunit.cache"
6-
executionOrder="depends,defects"
7-
beStrictAboutCoverageMetadata="true"
8-
beStrictAboutOutputDuringTests="true"
9-
colors="true"
10-
backupGlobals="false"
11-
backupStaticProperties="false"
12-
stopOnError="false"
13-
stopOnFailure="false">
14-
<testsuites>
15-
<testsuite name="BeyondCode Test Suite">
16-
<directory>tests</directory>
17-
</testsuite>
18-
</testsuites>
19-
20-
<source restrictDeprecations="true" restrictNotices="true" restrictWarnings="true">
21-
<include>
22-
<directory>src</directory>
23-
</include>
24-
</source>
25-
26-
<logging>
27-
<junit outputFile="build/report.junit.xml"/>
28-
</logging>
29-
30-
<coverage>
31-
<report>
32-
<html outputDirectory="build/html-coverage" />
33-
<text outputFile="build/coverage.txt" />
34-
<clover outputFile="build/clover.xml" />
35-
</report>
36-
</coverage>
2+
<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">
3+
<testsuites>
4+
<testsuite name="BeyondCode Test Suite">
5+
<directory>tests</directory>
6+
</testsuite>
7+
</testsuites>
8+
<source restrictNotices="true" restrictWarnings="true" ignoreIndirectDeprecations="true">
9+
<include>
10+
<directory>src</directory>
11+
</include>
12+
</source>
13+
<logging>
14+
<junit outputFile="build/report.junit.xml"/>
15+
</logging>
16+
<coverage>
17+
<report>
18+
<html outputDirectory="build/html-coverage"/>
19+
<text outputFile="build/coverage.txt"/>
20+
<clover outputFile="build/clover.xml"/>
21+
</report>
22+
</coverage>
3723
</phpunit>

phpunit.xml.dist.bak

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
5+
cacheDirectory=".phpunit.cache"
6+
executionOrder="depends,defects"
7+
beStrictAboutCoverageMetadata="true"
8+
beStrictAboutOutputDuringTests="true"
9+
colors="true"
10+
backupGlobals="false"
11+
backupStaticProperties="false"
12+
stopOnError="false"
13+
stopOnFailure="false">
14+
<testsuites>
15+
<testsuite name="BeyondCode Test Suite">
16+
<directory>tests</directory>
17+
</testsuite>
18+
</testsuites>
19+
20+
<source restrictDeprecations="true" restrictNotices="true" restrictWarnings="true">
21+
<include>
22+
<directory>src</directory>
23+
</include>
24+
</source>
25+
26+
<logging>
27+
<junit outputFile="build/report.junit.xml"/>
28+
</logging>
29+
30+
<coverage>
31+
<report>
32+
<html outputDirectory="build/html-coverage" />
33+
<text outputFile="build/coverage.txt" />
34+
<clover outputFile="build/clover.xml" />
35+
</report>
36+
</coverage>
37+
</phpunit>

src/CreatesMailers.php

Lines changed: 5 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -4,116 +4,21 @@
44

55
use Illuminate\Support\Arr;
66
use Illuminate\Support\Str;
7-
use Swift_Mailer;
87

98
trait CreatesMailers
109
{
11-
protected function createLaravel6Mailer($app)
12-
{
13-
$config = $this->getConfig();
14-
15-
// Once we have create the mailer instance, we will set a container instance
16-
// on the mailer. This allows us to resolve mailer classes via containers
17-
// for maximum testability on said classes instead of passing Closures.
18-
$mailer = new Mailer(
19-
$app['view'],
20-
$app['swift.mailer'],
21-
$app['events']
22-
);
23-
24-
if ($app->bound('queue')) {
25-
$mailer->setQueue($app['queue']);
26-
}
27-
28-
// Next we will set all of the global addresses on this mailer, which allows
29-
// for easy unification of all "from" addresses as well as easy debugging
30-
// of sent messages since they get be sent into a single email address.
31-
foreach (['from', 'reply_to', 'to'] as $type) {
32-
$this->setGlobalAddress($mailer, $config, $type);
33-
}
34-
35-
return $mailer;
36-
}
37-
38-
protected function createLaravel7Mailer($app)
39-
{
40-
$defaultDriver = $app['mail.manager']->getDefaultDriver();
41-
$config = $this->getConfig($defaultDriver);
42-
43-
// Laravel 7 no longer bindes the swift.mailer:
44-
$swiftMailer = new Swift_Mailer($app['mail.manager']->createTransport($config));
45-
46-
// Once we have create the mailer instance, we will set a container instance
47-
// on the mailer. This allows us to resolve mailer classes via containers
48-
// for maximum testability on said classes instead of passing Closures.
49-
$mailer = new Laravel7Mailer(
50-
'smtp',
51-
$app['view'],
52-
$swiftMailer,
53-
$app['events']
54-
);
55-
56-
if ($app->bound('queue')) {
57-
$mailer->setQueue($app['queue']);
58-
}
59-
60-
// Next we will set all of the global addresses on this mailer, which allows
61-
// for easy unification of all "from" addresses as well as easy debugging
62-
// of sent messages since they get be sent into a single email address.
63-
foreach (['from', 'reply_to', 'to', 'return_path'] as $type) {
64-
$this->setGlobalAddress($mailer, $config, $type);
65-
}
66-
67-
return $mailer;
68-
}
69-
70-
protected function createLaravel8Mailer($app)
10+
protected function createGeneralLaravelMailer($app)
7111
{
7212
$defaultDriver = $app['mail.manager']->getDefaultDriver();
7313
$config = $this->getConfig($defaultDriver);
7414

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

7718
// Once we have create the mailer instance, we will set a container instance
7819
// on the mailer. This allows us to resolve mailer classes via containers
7920
// for maximum testability on said classes instead of passing Closures.
80-
$mailer = new Laravel8Mailer(
81-
'smtp',
82-
$app['view'],
83-
$swiftMailer,
84-
$app['events']
85-
);
86-
87-
if ($app->bound('queue')) {
88-
$mailer->setQueue($app['queue']);
89-
}
90-
91-
// Next we will set all of the global addresses on this mailer, which allows
92-
// for easy unification of all "from" addresses as well as easy debugging
93-
// of sent messages since they get be sent into a single email address.
94-
foreach (['from', 'reply_to', 'to', 'return_path'] as $type) {
95-
$this->setGlobalAddress($mailer, $config, $type);
96-
}
97-
98-
return $mailer;
99-
}
100-
101-
protected function createLaravel9Mailer($app)
102-
{
103-
$defaultDriver = $app['mail.manager']->getDefaultDriver();
104-
$config = $this->getConfig($defaultDriver);
105-
106-
// We get Symfony Transport from Laravel 9 mailer
107-
if (version_compare(app()->version(), '10.0.0', '<')) {
108-
$symfonyTransport = $app['mail.manager']->getSymfonyTransport();
109-
} else {
110-
$symfonyTransport = $app['mailer']->getSymfonyTransport();
111-
}
112-
113-
// Once we have create the mailer instance, we will set a container instance
114-
// on the mailer. This allows us to resolve mailer classes via containers
115-
// for maximum testability on said classes instead of passing Closures.
116-
$mailer = new Laravel9Mailer(
21+
$mailer = new GeneralLaravelMailer(
11722
'smtp',
11823
$app['view'],
11924
$symfonyTransport,
@@ -152,11 +57,7 @@ protected function getConfig($name = 'smtp')
15257
*/
15358
protected function setGlobalAddress($mailer, array $config, $type)
15459
{
155-
if (version_compare(app()->version(), '7.0.0', '<')) {
156-
$address = Arr::get($config, $type);
157-
} else {
158-
$address = Arr::get($config, $type, $this->app['config']['mail.'.$type]);
159-
}
60+
$address = Arr::get($config, $type, $this->app['config']['mail.'.$type]);
16061

16162
if (is_array($address) && isset($address['address'])) {
16263
$mailer->{'always'.Str::studly($type)}($address['address'], $address['name']);

src/Laravel8Mailer.php renamed to src/GeneralLaravelMailer.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,19 @@
55
use Illuminate\Contracts\Mail\Factory as MailFactory;
66
use Illuminate\Contracts\Mail\Mailer as MailerContract;
77

8-
class Laravel8Mailer extends Laravel7Mailer implements MailerContract, MailFactory
8+
class GeneralLaravelMailer extends Mailer implements MailerContract, MailFactory
99
{
10+
public $currentMailer = null;
11+
protected $app;
12+
protected $mailers = [];
13+
14+
public function mailer($name = null)
15+
{
16+
$this->currentMailer = $name;
17+
18+
return $this;
19+
}
20+
1021
/**
1122
* Set laravel application.
1223
*

src/HeloLaravelServiceProvider.php

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,30 +45,16 @@ public function register()
4545
$this->mergeConfigFrom(__DIR__.'/../config/helo.php', 'helo');
4646

4747
$this->app->singleton(Mailer::class, function ($app) {
48-
$version = $this->version($app);
49-
50-
if ($version < 7) {
51-
return $this->createLaravel6Mailer($app);
52-
}
53-
54-
if ($version < 8) {
55-
return $this->createLaravel7Mailer($app);
56-
}
57-
58-
if ($version < 9) {
59-
return $this->createLaravel8Mailer($app);
60-
}
61-
62-
return $this->createLaravel9Mailer($app);
48+
return $this->createGeneralLaravelMailer($app);
6349
});
6450
}
6551

6652
protected function bootMailable()
6753
{
54+
$managerInstance = app()->make(MailManager::class, ['app' => app()]);
6855
$instance = app()->make(Mailer::class);
6956

70-
Mail::swap($instance);
71-
57+
Mail::swap($managerInstance);
7258
$this->app->instance(MailerContract::class, $instance);
7359
}
7460

src/Laravel7Mailer.php

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/Laravel9Mailer.php

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/MailManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class MailManager extends LaravelMailManager implements FactoryContract
1212
public function mailer($name = null)
1313
{
1414
if (!$name) {
15-
return $this->createLaravel9Mailer($this->app);
15+
return $this->createGeneralLaravelMailer($this->app);
1616
}
1717

1818
return $this->mailers[$name] = $this->get($name);

0 commit comments

Comments
 (0)