Skip to content

Commit

Permalink
fix: 🐛 Mock Swift_Mailer instead of Mail\Mailer
Browse files Browse the repository at this point in the history
  • Loading branch information
mpyw committed Jun 28, 2021
1 parent 10dc8c7 commit dbf9dc0
Showing 1 changed file with 6 additions and 21 deletions.
27 changes: 6 additions & 21 deletions tests/Feature/InitializingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -31,6 +29,7 @@
use Mpyw\LaravelCachedDatabaseStickiness\Tests\Stubs\Notifications\ModifiedNotification;
use Orchestra\Testbench\TestCase;
use ReflectionProperty;
use Swift_Mailer;

class InitializingTest extends TestCase
{
Expand Down Expand Up @@ -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());
Expand All @@ -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();

Expand Down

0 comments on commit dbf9dc0

Please sign in to comment.