Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] Use MailManager as underlying passthru object for MailFake #46055

Merged
merged 2 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/Illuminate/Support/Testing/Fakes/MailFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Contracts\Mail\Mailer;
use Illuminate\Contracts\Mail\MailQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\MailManager;
use Illuminate\Support\Traits\ForwardsCalls;
use Illuminate\Support\Traits\ReflectsClosures;
use PHPUnit\Framework\Assert as PHPUnit;
Expand All @@ -19,9 +20,9 @@ class MailFake implements Factory, Mailer, MailQueue
/**
* The mailer instance.
*
* @var Mailer
* @var MailManager
*/
protected $mailer;
protected $manager;

/**
* The mailer currently being used to send a message.
Expand All @@ -47,12 +48,12 @@ class MailFake implements Factory, Mailer, MailQueue
/**
* Create a new mail fake.
*
* @param Mailer $mailer
* @param MailManager $manager
* @return void
*/
public function __construct(Mailer $mailer)
public function __construct(MailManager $manager)
{
$this->mailer = $mailer;
$this->manager = $manager;
}

/**
Expand Down Expand Up @@ -460,6 +461,6 @@ public function forgetMailers()
*/
public function __call($method, $parameters)
{
return $this->forwardCallTo($this->mailer, $method, $parameters);
return $this->forwardCallTo($this->manager, $method, $parameters);
}
}
31 changes: 31 additions & 0 deletions tests/Support/SupportMailTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Illuminate\Tests\Support;

use Illuminate\Support\Facades\Mail;
use Orchestra\Testbench\TestCase;

class SupportMailTest extends TestCase
{
public function testItRegisterAndCallMacros()
{
Mail::macro('test', fn (string $str) => $str === 'foo'
? 'it works!'
: 'it failed.',
);

$this->assertEquals('it works!', Mail::test('foo'));
}

public function testItRegisterAndCallMacrosWhenFaked()
{
Mail::macro('test', fn (string $str) => $str === 'foo'
? 'it works!'
: 'it failed.',
);

Mail::fake();

$this->assertEquals('it works!', Mail::test('foo'));
}
}
10 changes: 5 additions & 5 deletions tests/Support/SupportTestingMailFakeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Contracts\Translation\HasLocalePreference;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailer;
use Illuminate\Mail\MailManager;
use Illuminate\Support\Testing\Fakes\MailFake;
use Mockery as m;
use PHPUnit\Framework\ExpectationFailedException;
Expand All @@ -16,7 +16,7 @@ class SupportTestingMailFakeTest extends TestCase
/**
* @var \Mockery
*/
private $mailer;
private $mailManager;

/**
* @var \Illuminate\Support\Testing\Fakes\MailFake
Expand All @@ -31,8 +31,8 @@ class SupportTestingMailFakeTest extends TestCase
protected function setUp(): void
{
parent::setUp();
$this->mailer = m::mock(Mailer::class);
$this->fake = new MailFake($this->mailer);
$this->mailManager = m::mock(MailManager::class);
$this->fake = new MailFake($this->mailManager);
$this->mailable = new MailableStub;
}

Expand Down Expand Up @@ -224,7 +224,7 @@ public function testAssertSentWithClosure()

public function testMissingMethodsAreForwarded()
{
$this->mailer->shouldReceive('foo')->andReturn('bar');
$this->mailManager->shouldReceive('foo')->andReturn('bar');

$this->assertEquals('bar', $this->fake->foo());
}
Expand Down