Skip to content
This repository has been archived by the owner on Apr 8, 2024. It is now read-only.

Commit

Permalink
Merge branch 'release/1.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
ssfinney committed Apr 20, 2020
2 parents 4f56cc9 + d077235 commit 9ee60a9
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 26 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ matrix:
- php: 7.3
- php: 7.3
env: SETUP=lowest
- php: 7.4
- php: 7.4
env: SETUP=lowest

sudo: false

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.1
1.3.0
16 changes: 11 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,23 @@
{
"name": "Jimmy Puckett",
"email": "jimmy.puckett@spinen.com"
},
{
"name": "Stephen Finney",
"email": "stephen.finney@spinen.com"
}
],
"require": {
"php": ">=7.2",
"illuminate/support": "~5.5|~6",
"swiftmailer/swiftmailer": "~6.0",
"phpunit/phpunit": "~7.0.1|~8.0"
"illuminate/container": "~5.7|~6|~7",
"illuminate/mail": "~5.7|~6|~7",
"swiftmailer/swiftmailer": "~6.2",
"phpunit/phpunit": "^8.4|^9.0"
},
"require-dev": {
"mockery/mockery": "^1",
"psy/psysh": "^0.9.9",
"egulias/email-validator": "^2.1.16",
"mockery/mockery": "^1.3.1",
"psy/psysh": "^0.10",
"symfony/thanks": "^1.1",
"symfony/var-dumper": "~3.0|^4.2"
},
Expand Down
3 changes: 1 addition & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="true"
processIsolation="false"
stopOnFailure="false"
verbose="true">

Expand Down Expand Up @@ -48,7 +48,6 @@
showOnlySummary="true"
showUncoveredFiles="false"/>
<log type="coverage-clover" target="build/phpunit/logs/clover.xml"/>
<log type="json" target="./build/phpunit/logs/logfile.json"/>
<log type="junit" target="./build/phpunit/logs/junit.xml"/>
</logging>
</phpunit>
45 changes: 29 additions & 16 deletions src/MailTracking.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Spinen\MailAssertions;

use Illuminate\Support\Facades\Mail;
use Illuminate\Container\Container;
use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Contracts\Mail\Mailer;
use Swift_Message;

/**
Expand Down Expand Up @@ -48,15 +50,30 @@ trait MailTracking
public function setUpMailTracking()
{
$register_plugin = function () {
Mail::getSwiftMailer()
->registerPlugin(new MailRecorder($this));
$this->resolveMailer()
->getSwiftMailer()
->registerPlugin(new MailRecorder($this));
};

$this->afterApplicationCreated(function () use ($register_plugin) {
$register_plugin();
});
}

/**
* Resolve the mailer from the IoC
*
* We are staying away from the Mail facade, so that we can support PHP 7.4 with Laravel 5.x
*
* @return Mailer
* @throws BindingResolutionException
*/
protected function resolveMailer()
{
return Container::getInstance()
->make(Mailer::class);
}

/**
* Retrieve the appropriate Swift message.
*
Expand Down Expand Up @@ -133,8 +150,8 @@ protected function seeEmailCc($cc, Swift_Message $message = null)
*/
protected function seeEmailContains($excerpt, Swift_Message $message = null)
{
$this->assertContains($excerpt, $this->getEmail($message)
->getBody(), "The last email sent did not contain the provided body.");
$this->assertStringContainsString($excerpt, $this->getEmail($message)
->getBody(), "The last email sent did not contain the provided body.");

return $this;
}
Expand Down Expand Up @@ -167,9 +184,8 @@ protected function seeEmailContentTypeEquals($content_type, Swift_Message $messa
*/
protected function seeEmailDoesNotContain($excerpt, Swift_Message $message = null)
{
$this->assertNotContains($excerpt, $this->getEmail($message)
->getBody(),
"The last email sent contained the provided text in its body.");
$this->assertStringNotContainsString($excerpt, $this->getEmail($message)
->getBody(), "The last email sent contained the provided text in its body.");

return $this;
}
Expand Down Expand Up @@ -297,9 +313,8 @@ protected function seeEmailSubject($subject, Swift_Message $message = null)
*/
protected function seeEmailSubjectContains($excerpt, Swift_Message $message = null)
{
$this->assertContains($excerpt, $this->getEmail($message)
->getSubject(),
"The last email sent did not contain the provided subject.");
$this->assertStringContainsString($excerpt, $this->getEmail($message)
->getSubject(), "The last email sent did not contain the provided subject.");

return $this;
}
Expand All @@ -314,9 +329,8 @@ protected function seeEmailSubjectContains($excerpt, Swift_Message $message = nu
*/
protected function seeEmailSubjectDoesNotContain($excerpt, Swift_Message $message = null)
{
$this->assertNotContains($excerpt, $this->getEmail($message)
->getSubject(),
"The last email sent contained the provided text in its subject.");
$this->assertStringNotContainsString($excerpt, $this->getEmail($message)
->getSubject(), "The last email sent contained the provided text in its subject.");

return $this;
}
Expand All @@ -332,8 +346,7 @@ protected function seeEmailSubjectDoesNotContain($excerpt, Swift_Message $messag
protected function seeEmailSubjectEquals($subject, Swift_Message $message = null)
{
$this->assertEquals($subject, $this->getEmail($message)
->getSubject(),
"The last email sent did not contain a subject of $subject.");
->getSubject(), "The last email sent did not contain a subject of $subject.");

return $this;
}
Expand Down
14 changes: 12 additions & 2 deletions tests/MailTrackingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

namespace Spinen\MailAssertions;

use Illuminate\Support\Facades\Mail;
use Illuminate\Container\Container;
use Illuminate\Contracts\Mail\Mailer;
use Mockery;
use ReflectionClass;
use Spinen\MailAssertions\Stubs\MailTrackingStub as MailTracking;
Expand All @@ -21,12 +22,21 @@ class MailTrackingTest extends TestCase
*/
protected $mail_tracking;

/**
* @var Mockery\Mock
*/
protected $mailer_mock;

/**
* Make a new MailTracking (Stub) instance for each test
*/
protected function setUp(): void
{
$this->mail_tracking = new MailTracking();
$this->mailer_mock = Mockery::mock(Mailer::class);

Container::getInstance()
->instance(Mailer::class, $this->mailer_mock);

parent::setUp();
}
Expand Down Expand Up @@ -104,7 +114,7 @@ public function it_registers_MailRecorder_withMail_in_the_setup_with_before_anno
}))
->andReturnNull();

Mail::shouldReceive('getSwiftMailer')
$this->mailer_mock->shouldReceive('getSwiftMailer')
->once()
->withNoArgs()
->andReturn($swift_mock);
Expand Down

0 comments on commit 9ee60a9

Please sign in to comment.