From dbf9dc07821576fbf823a3f06eef2c1293830f49 Mon Sep 17 00:00:00 2001 From: mpyw Date: Tue, 29 Jun 2021 01:07:30 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Mock=20Swift=5FMailer=20i?= =?UTF-8?q?nstead=20of=20Mail\Mailer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Feature/InitializingTest.php | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/tests/Feature/InitializingTest.php b/tests/Feature/InitializingTest.php index 875f239..6121e55 100644 --- a/tests/Feature/InitializingTest.php +++ b/tests/Feature/InitializingTest.php @@ -2,8 +2,6 @@ namespace Mpyw\LaravelCachedDatabaseStickiness\Tests\Feature; -use Illuminate\Contracts\Mail\Factory as MailerFactory; -use Illuminate\Contracts\Mail\Mailer; use Illuminate\Http\Request; use Illuminate\Notifications\AnonymousNotifiable; use Illuminate\Support\Facades\Bus; @@ -31,6 +29,7 @@ use Mpyw\LaravelCachedDatabaseStickiness\Tests\Stubs\Notifications\ModifiedNotification; use Orchestra\Testbench\TestCase; use ReflectionProperty; +use Swift_Mailer; class InitializingTest extends TestCase { @@ -177,16 +176,6 @@ public function testInitializationForListeners(): void public function testInitializationForNotifications(): void { - $this->mock(Mailer::class)->shouldReceive('send'); - - // [7.x] Multiple Mailers Per App - // https://github.com/laravel/framework/pull/31073 - if (interface_exists(MailerFactory::class)) { - $this->mock(MailerFactory::class) - ->shouldReceive('mailer') - ->andReturn($this->app->make(Mailer::class)); - } - DB::connection(); $this->assertFalse($this->getRecordsModifiedViaReflection()); @@ -209,15 +198,11 @@ public function testInitializationForNotifications(): void public function testInitializationForMailables(): void { - $this->mock(Mailer::class)->shouldReceive('send'); - - // [7.x] Multiple Mailers Per App - // https://github.com/laravel/framework/pull/31073 - if (interface_exists(MailerFactory::class)) { - $this->mock(MailerFactory::class) - ->shouldReceive('mailer') - ->andReturn($this->app->make(Mailer::class)); - } + $swift = $this->mock(Swift_Mailer::class)->makePartial(); + $swift->shouldReceive('send')->times(3)->andReturn(1); + $swift->shouldReceive('getTransport->stop')->times(3); + + Mail::setSwiftMailer($swift); DB::connection();