Skip to content

Commit

Permalink
Splitted Mailer for Laravel 7 and previous versions
Browse files Browse the repository at this point in the history
  • Loading branch information
zupolgec committed Apr 23, 2020
1 parent 0c17b27 commit d584333
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/HeloLaravelServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public function register()
], 'config');
}


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

$this->app->singleton(Mailer::class, function ($app) {
Expand Down Expand Up @@ -93,7 +92,7 @@ protected function createLaravel7Mailer($app)
// 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(
$mailer = new Laravel7Mailer(
'smtp', $app['view'], $swiftMailer, $app['events']
);

Expand Down
16 changes: 16 additions & 0 deletions src/Laravel7Mailer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace BeyondCode\HeloLaravel;

use Illuminate\Contracts\Mail\Factory as MailFactory;
use Illuminate\Contracts\Mail\Mailer as MailerContract;

class Laravel7Mailer extends Mailer implements MailerContract, MailFactory
{
public function mailer($name = null)
{
$this->currentMailer = $name;

return $this;
}
}
16 changes: 15 additions & 1 deletion tests/HeloTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
namespace BeyondCode\HeloLaravel\Tests;

use BeyondCode\HeloLaravel\HeloLaravelServiceProvider;
use BeyondCode\HeloLaravel\Mailer;
use BeyondCode\HeloLaravel\Laravel7Mailer;
use BeyondCode\HeloLaravel\TestMail;
use BeyondCode\HeloLaravel\TestMailCommand;
use Illuminate\Support\Facades\Mail;
use Orchestra\Testbench\TestCase;

class HeloTest extends TestCase
{
protected function getPackageProviders()
protected function getPackageProviders($app)
{
return [
HeloLaravelServiceProvider::class
Expand All @@ -26,4 +28,16 @@ public function test_the_mail_commands_sends_the_mailable()

Mail::assertSent(TestMail::class);
}

/** @test */
public function test_the_correct_mailer_is_binded()
{
$mailer = app(Mailer::class);

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

0 comments on commit d584333

Please sign in to comment.