From 9a14de8e2101697220403b5ee911f0fd8fca5b45 Mon Sep 17 00:00:00 2001 From: Adam Nielsen <1765602+iwasherefirst2@users.noreply.github.com> Date: Sat, 23 Nov 2019 18:23:17 +0100 Subject: [PATCH] Refactor test class --- tests/TestCase.php | 28 ++++++++++++++++++++++++++++ tests/Unit/MultiMailTest.php | 31 ------------------------------- 2 files changed, 28 insertions(+), 31 deletions(-) diff --git a/tests/TestCase.php b/tests/TestCase.php index 0efd94e..acb3d31 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,13 +2,26 @@ namespace IWasHereFirst2\LaravelMultiMail\Tests; +use IWasHereFirst2\LaravelMultiMail\Facades\MultiMail; + use IWasHereFirst2\LaravelMultiMail\MultiMailServiceProvider; +use Swift_Events_EventListener; +use Swift_Message; class TestCase extends \Orchestra\Testbench\TestCase { + protected $emails; + public function setUp(): void { parent::setUp(); + + MultiMail::registerPlugin(new TestingMailEventListener($this)); + } + + public function addEmail(Swift_Message $email) + { + $this->emails[] = $email; } /** @@ -40,3 +53,18 @@ protected function getEnvironmentSetUp($app) ]); } } + +class TestingMailEventListener implements Swift_Events_EventListener +{ + protected $test; + + public function __construct($test) + { + $this->test = $test; + } + + public function beforeSendPerformed($event) + { + $this->test->addEmail($event->getMessage()); + } +} diff --git a/tests/Unit/MultiMailTest.php b/tests/Unit/MultiMailTest.php index 41784ec..34d13ff 100644 --- a/tests/Unit/MultiMailTest.php +++ b/tests/Unit/MultiMailTest.php @@ -6,22 +6,11 @@ use Illuminate\Support\Facades\View; use IWasHereFirst2\LaravelMultiMail\Facades\MultiMail; use IWasHereFirst2\LaravelMultiMail\Tests\TestCase; -use Swift_Events_EventListener; -use Swift_Message; class MultiMailTest extends TestCase { const FROM = 'test@fake.de'; - protected $emails; - - public function setUp(): void - { - parent::setUp(); - - MultiMail::registerPlugin(new TestingMailEventListener($this)); - } - /** @test */ public function check_if_mail_is_sendable() { @@ -62,11 +51,6 @@ protected function getEnvironmentSetUp($app) View::addLocation(__DIR__ . '/Fixtures'); } - - public function addEmail(Swift_Message $email) - { - $this->emails[] = $email; - } } class TestMail extends Mailable @@ -81,18 +65,3 @@ public function build() return $this->view('view'); } } - -class TestingMailEventListener implements Swift_Events_EventListener -{ - protected $test; - - public function __construct($test) - { - $this->test = $test; - } - - public function beforeSendPerformed($event) - { - $this->test->addEmail($event->getMessage()); - } -}