Skip to content

Commit dffa167

Browse files
authored
Merge pull request #11 from zupolgec/fix-laravel7-new-mailer
Splitted Mailer for Laravel 7 and previous versions
2 parents 0c17b27 + d584333 commit dffa167

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

src/HeloLaravelServiceProvider.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public function register()
4545
], 'config');
4646
}
4747

48-
4948
$this->mergeConfigFrom(__DIR__.'/../config/helo.php', 'helo');
5049

5150
$this->app->singleton(Mailer::class, function ($app) {
@@ -93,7 +92,7 @@ protected function createLaravel7Mailer($app)
9392
// Once we have create the mailer instance, we will set a container instance
9493
// on the mailer. This allows us to resolve mailer classes via containers
9594
// for maximum testability on said classes instead of passing Closures.
96-
$mailer = new Mailer(
95+
$mailer = new Laravel7Mailer(
9796
'smtp', $app['view'], $swiftMailer, $app['events']
9897
);
9998

src/Laravel7Mailer.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace BeyondCode\HeloLaravel;
4+
5+
use Illuminate\Contracts\Mail\Factory as MailFactory;
6+
use Illuminate\Contracts\Mail\Mailer as MailerContract;
7+
8+
class Laravel7Mailer extends Mailer implements MailerContract, MailFactory
9+
{
10+
public function mailer($name = null)
11+
{
12+
$this->currentMailer = $name;
13+
14+
return $this;
15+
}
16+
}

tests/HeloTest.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
namespace BeyondCode\HeloLaravel\Tests;
44

55
use BeyondCode\HeloLaravel\HeloLaravelServiceProvider;
6+
use BeyondCode\HeloLaravel\Mailer;
7+
use BeyondCode\HeloLaravel\Laravel7Mailer;
68
use BeyondCode\HeloLaravel\TestMail;
79
use BeyondCode\HeloLaravel\TestMailCommand;
810
use Illuminate\Support\Facades\Mail;
911
use Orchestra\Testbench\TestCase;
1012

1113
class HeloTest extends TestCase
1214
{
13-
protected function getPackageProviders()
15+
protected function getPackageProviders($app)
1416
{
1517
return [
1618
HeloLaravelServiceProvider::class
@@ -26,4 +28,16 @@ public function test_the_mail_commands_sends_the_mailable()
2628

2729
Mail::assertSent(TestMail::class);
2830
}
31+
32+
/** @test */
33+
public function test_the_correct_mailer_is_binded()
34+
{
35+
$mailer = app(Mailer::class);
36+
37+
if (version_compare(app()->version(), '7.0.0', '<')) {
38+
$this->assertTrue($mailer instanceof Mailer);
39+
} else {
40+
$this->assertTrue($mailer instanceof Laravel7Mailer);
41+
}
42+
}
2943
}

0 commit comments

Comments
 (0)