Skip to content

Commit 98aba43

Browse files
committed
update package so it works with all laravel versions
1 parent e7b0501 commit 98aba43

7 files changed

+27
-31
lines changed

src/Email.php

+12-3
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ public function hasFrom()
348348
*/
349349
public function hasCc()
350350
{
351-
return strlen($this->getOriginal('cc')) > 0;
351+
return strlen($this->getRawDatabaseValue('cc')) > 0;
352352
}
353353

354354
/**
@@ -358,7 +358,7 @@ public function hasCc()
358358
*/
359359
public function hasBcc()
360360
{
361-
return strlen($this->getOriginal('bcc')) > 0;
361+
return strlen($this->getRawDatabaseValue('bcc')) > 0;
362362
}
363363

364364
/**
@@ -378,7 +378,7 @@ public function isScheduled()
378378
*/
379379
public function isEncrypted()
380380
{
381-
return (bool) $this->getOriginal('encrypted');
381+
return (bool) $this->getRawDatabaseValue('encrypted');
382382
}
383383

384384
/**
@@ -479,4 +479,13 @@ public function retry()
479479

480480
$retry->save();
481481
}
482+
483+
public function getRawDatabaseValue($key = null, $default = null)
484+
{
485+
if (method_exists($this, 'getRawOriginal')) {
486+
return $this->getRawOriginal($key, $default);
487+
}
488+
489+
return $this->getOriginal($key, $default);
490+
}
482491
}

src/Sender.php

+2-12
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace Stackkit\LaravelDatabaseEmails;
44

5-
use Illuminate\Mail\Mailer;
65
use Illuminate\Mail\Message;
6+
use Illuminate\Support\Facades\Mail;
77

88
class Sender
99
{
@@ -20,23 +20,13 @@ public function send(Email $email)
2020

2121
$email->markAsSending();
2222

23-
$this->getMailerInstance()->send([], [], function (Message $message) use ($email) {
23+
Mail::send([], [], function (Message $message) use ($email) {
2424
$this->buildMessage($message, $email);
2525
});
2626

2727
$email->markAsSent();
2828
}
2929

30-
/**
31-
* Get the instance of the Laravel mailer.
32-
*
33-
* @return Mailer
34-
*/
35-
private function getMailerInstance()
36-
{
37-
return app('mailer');
38-
}
39-
4030
/**
4131
* Build the e-mail message.
4232
*

tests/EncryptionTest.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function the_recipient_should_be_encrypted_and_decrypted()
2626
{
2727
$email = $this->sendEmail(['recipient' => '[email protected]']);
2828

29-
$this->assertEquals('[email protected]', decrypt($email->getOriginal('recipient')));
29+
$this->assertEquals('[email protected]', decrypt($email->getRawDatabaseValue('recipient')));
3030

3131
$this->assertEquals('[email protected]', $email->getRecipient());
3232
}
@@ -39,8 +39,8 @@ public function cc_and_bb_should_be_encrypted_and_decrypted()
3939
'bcc' => $bcc = ['[email protected]', '[email protected]'],
4040
]);
4141

42-
$this->assertEquals($cc, decrypt($email->getOriginal('cc')));
43-
$this->assertEquals($bcc, decrypt($email->getOriginal('bcc')));
42+
$this->assertEquals($cc, decrypt($email->getRawDatabaseValue('cc')));
43+
$this->assertEquals($bcc, decrypt($email->getRawDatabaseValue('bcc')));
4444

4545
$this->assertEquals($cc, $email->getCc());
4646
$this->assertEquals($bcc, $email->getBcc());
@@ -51,7 +51,7 @@ public function the_subject_should_be_encrypted_and_decrypted()
5151
{
5252
$email = $this->sendEmail(['subject' => 'test subject']);
5353

54-
$this->assertEquals('test subject', decrypt($email->getOriginal('subject')));
54+
$this->assertEquals('test subject', decrypt($email->getRawDatabaseValue('subject')));
5555

5656
$this->assertEquals('test subject', $email->getSubject());
5757
}
@@ -63,7 +63,7 @@ public function the_variables_should_be_encrypted_and_decrypted()
6363

6464
$this->assertEquals(
6565
['name' => 'Jane Doe'],
66-
decrypt($email->getOriginal('variables'))
66+
decrypt($email->getRawDatabaseValue('variables'))
6767
);
6868

6969
$this->assertEquals(
@@ -79,7 +79,7 @@ public function the_body_should_be_encrypted_and_decrypted()
7979

8080
$expectedBody = "Name: Jane Doe\n";
8181

82-
$this->assertEquals($expectedBody, decrypt($email->getOriginal('body')));
82+
$this->assertEquals($expectedBody, decrypt($email->getRawDatabaseValue('body')));
8383

8484
$this->assertEquals($expectedBody, $email->getBody());
8585
}
@@ -94,7 +94,7 @@ public function from_should_be_encrypted_and_decrypted()
9494
'name' => 'Marick',
9595
];
9696

97-
$this->assertEquals($expect, decrypt($email->getOriginal('from')));
97+
$this->assertEquals($expect, decrypt($email->getRawDatabaseValue('from')));
9898
$this->assertEquals($expect, $email->getFrom());
9999
}
100100
}

tests/QueuedEmailsTest.php

-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ class QueuedEmailsTest extends TestCase
1111
public function setUp(): void
1212
{
1313
parent::setUp();
14-
15-
Mail::getSwiftMailer()->registerPlugin(new TestingMailEventListener($this));
1614
}
1715

1816
/** @test */

tests/SendEmailsCommandTest.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ public function an_email_should_not_be_sent_once_it_is_marked_as_sent()
3939

4040
$this->assertNotNull($firstSend = $email->fresh()->getSendDate());
4141

42-
sleep(1);
43-
4442
$this->artisan('email:send');
4543

4644
$this->assertEquals(1, $email->fresh()->getAttempts());
@@ -50,14 +48,14 @@ public function an_email_should_not_be_sent_once_it_is_marked_as_sent()
5048
/** @test */
5149
public function if_an_email_fails_to_be_sent_it_should_be_logged_in_the_database()
5250
{
53-
$this->app['config']['mail.driver'] = 'does-not-exist';
54-
5551
$email = $this->sendEmail();
5652

53+
$email->update(['recipient' => 'asdf']);
54+
5755
$this->artisan('email:send');
5856

5957
$this->assertTrue($email->fresh()->hasFailed());
60-
$this->assertStringContains('Driver [does-not-exist] not supported.', $email->fresh()->getError());
58+
$this->assertStringContains('Swift_RfcComplianceException', $email->fresh()->getError());
6159
}
6260

6361
/** @test */

tests/SenderTest.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ public function it_sends_an_email()
2424
{
2525
$this->sendEmail();
2626

27-
Mail::shouldReceive('send')
28-
->once();
27+
Mail::shouldReceive('send')->once();
2928

3029
$this->artisan('email:send');
3130
}

tests/TestCase.php

+2
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ protected function getEnvironmentSetUp($app)
9292
'prefix' => '',
9393
'strict' => true,
9494
]);
95+
96+
$app['config']->set('mail.driver', 'log');
9597
}
9698

9799
public function createEmail($overwrite = [])

0 commit comments

Comments
 (0)