Skip to content

Commit

Permalink
Refactor test class
Browse files Browse the repository at this point in the history
  • Loading branch information
iwasherefirst2 committed Nov 23, 2019
1 parent 6e17030 commit 9a14de8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 31 deletions.
28 changes: 28 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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());
}
}
31 changes: 0 additions & 31 deletions tests/Unit/MultiMailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '[email protected]';

protected $emails;

public function setUp(): void
{
parent::setUp();

MultiMail::registerPlugin(new TestingMailEventListener($this));
}

/** @test */
public function check_if_mail_is_sendable()
{
Expand Down Expand Up @@ -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
Expand All @@ -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());
}
}

0 comments on commit 9a14de8

Please sign in to comment.