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

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
ssfinney committed Mar 16, 2018
2 parents c4d285d + 7950ed0 commit bbd7cfb
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 37 deletions.
14 changes: 8 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@
],
"require": {
"php": ">=5.5.0",
"illuminate/support": "~5.1.10|5.2.*|5.3.*|5.4.*|5.5.*",
"swiftmailer/swiftmailer": "~5.1|~6.0"
"illuminate/support": "~5.1.10|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*",
"swiftmailer/swiftmailer": "~5.1|~6.0",
"phpunit/phpunit": "~4.0|~5.0|~6.0|~7.0"
},
"require-dev": {
"mockery/mockery": "^0.9.1",
"phpunit/phpunit": "~4.0|~5.0",
"mockery/mockery": "~0.9",
"phpunit/phpunit": "~4.0",
"psy/psysh": "^0.5.1",
"satooshi/php-coveralls": "^0.6.1|^1",
"symfony/var-dumper": "~2.7|~3.0"
"satooshi/php-coveralls": "~1",
"symfony/thanks": "^1.0",
"symfony/var-dumper": "~3.0"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ NOTE: This is based off a video titled ["Testing Email With Custom Assertions"](
[![Latest Stable Version](https://poser.pugx.org/spinen/laravel-mail-assertions/v/stable)](https://packagist.org/packages/spinen/laravel-mail-assertions)
[![Total Downloads](https://poser.pugx.org/spinen/laravel-mail-assertions/downloads)](https://packagist.org/packages/spinen/laravel-mail-assertions)
[![Latest Unstable Version](https://poser.pugx.org/spinen/laravel-mail-assertions/v/unstable)](https://packagist.org/packages/spinen/laravel-mail-assertions#dev-master)
[![Dependency Status](https://www.versioneye.com/php/spinen:laravel-mail-assertions/0.1.1/badge.svg)](https://www.versioneye.com/php/spinen:laravel-mail-assertions/0.1.1)
[![Dependency Status](https://gemnasium.com/spinen/laravel-mail-assertions.png)](https://gemnasium.com/spinen/laravel-mail-assertions)
[![License](https://poser.pugx.org/spinen/laravel-mail-assertions/license)](https://packagist.org/packages/spinen/laravel-mail-assertions)

PHPUnit mail assertions for testing email in Laravel.
Expand Down
7 changes: 3 additions & 4 deletions src/MailRecorder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Spinen\MailAssertions;

use PHPUnit_Framework_TestCase;
use Swift_Events_EventListener;
use Swift_Events_SendEvent;

Expand All @@ -14,16 +13,16 @@
class MailRecorder implements Swift_Events_EventListener
{
/**
* @var PHPUnit_Framework_TestCase
* @var mixed
*/
protected $test;

/**
* MailRecorder constructor.
*
* @param PHPUnit_Framework_TestCase $test
* @param mixed $test The PhpUnit TestCase class to use
*/
public function __construct(PHPUnit_Framework_TestCase $test)
public function __construct($test)
{
$this->test = $test;
}
Expand Down
54 changes: 33 additions & 21 deletions src/MailTracking.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
namespace Spinen\MailAssertions;

use Illuminate\Support\Facades\Mail;
use PHPUnit_Framework_TestCase;
use Swift_Message;

/**
* Class MailTracking
*
* Trait to mixin to your test to allow for custom assertions when using PHPUnit with Laravel.
* Trait to mixin to your test to allow for custom assertions when using PHPUnit with Laravel. This trait assumes
* you are extending from the PHPUnit TestCase class (or a child of it).
*
* This originally started out as a copy & paste from a video series that Jeffrey Way did on laracasts.com. If you do
* not have an account on Laracasts, you should get one. It is an amazing resource to learn from. We used that
Expand Down Expand Up @@ -48,9 +48,21 @@ trait MailTracking
*/
public function setUpMailTracking()
{
$this->afterApplicationCreated(function () {
$register_plugin = function () {
Mail::getSwiftMailer()
->registerPlugin(new MailRecorder($this));
};

// To support Phpunit 5 and Laravel < 5.2, register the plugin normally
if (!method_exists($this, 'afterApplicationCreated')) {
$register_plugin();

return;
}

// For PhpUnit 6 and Laravel > 5.1, register the plugin after the app is booted
$this->afterApplicationCreated(function () use ($register_plugin) {
$register_plugin();
});
}

Expand Down Expand Up @@ -94,7 +106,7 @@ public function recordMail(Swift_Message $email)
* @param string $bcc
* @param Swift_Message|null $message
*
* @return PHPUnit_Framework_TestCase $this
* @return $this
*/
protected function seeEmailBcc($bcc, Swift_Message $message = null)
{
Expand All @@ -110,7 +122,7 @@ protected function seeEmailBcc($bcc, Swift_Message $message = null)
* @param string $cc
* @param Swift_Message|null $message
*
* @return PHPUnit_Framework_TestCase $this
* @return $this
*/
protected function seeEmailCc($cc, Swift_Message $message = null)
{
Expand All @@ -126,7 +138,7 @@ protected function seeEmailCc($cc, Swift_Message $message = null)
* @param string $excerpt
* @param Swift_Message|null $message
*
* @return PHPUnit_Framework_TestCase $this
* @return $this
*/
protected function seeEmailContains($excerpt, Swift_Message $message = null)
{
Expand All @@ -143,7 +155,7 @@ protected function seeEmailContains($excerpt, Swift_Message $message = null)
* @param string $content_type
* @param Swift_Message|null $message
*
* @return PHPUnit_Framework_TestCase $this
* @return $this
*/
protected function seeEmailContentTypeEquals($content_type, Swift_Message $message = null)
{
Expand All @@ -160,7 +172,7 @@ protected function seeEmailContentTypeEquals($content_type, Swift_Message $messa
* @param string $excerpt
* @param Swift_Message|null $message
*
* @return PHPUnit_Framework_TestCase $this
* @return $this
*/
protected function seeEmailDoesNotContain($excerpt, Swift_Message $message = null)
{
Expand All @@ -177,7 +189,7 @@ protected function seeEmailDoesNotContain($excerpt, Swift_Message $message = nul
* @param string $body
* @param Swift_Message|null $message
*
* @return PHPUnit_Framework_TestCase $this
* @return $this
*/
protected function seeEmailEquals($body, Swift_Message $message = null)
{
Expand All @@ -193,7 +205,7 @@ protected function seeEmailEquals($body, Swift_Message $message = null)
* @param string $sender
* @param Swift_Message|null $message
*
* @return PHPUnit_Framework_TestCase $this
* @return $this
*/
protected function seeEmailFrom($sender, Swift_Message $message = null)
{
Expand All @@ -211,7 +223,7 @@ protected function seeEmailFrom($sender, Swift_Message $message = null)
* @param integer $priority
* @param Swift_Message|null $message
*
* @return PHPUnit_Framework_TestCase $this
* @return $this
*/
protected function seeEmailPriorityEquals($priority, Swift_Message $message = null)
{
Expand All @@ -230,7 +242,7 @@ protected function seeEmailPriorityEquals($priority, Swift_Message $message = nu
* @param string $reply_to
* @param Swift_Message|null $message
*
* @return PHPUnit_Framework_TestCase $this
* @return $this
*/
protected function seeEmailReplyTo($reply_to, Swift_Message $message = null)
{
Expand All @@ -246,7 +258,7 @@ protected function seeEmailReplyTo($reply_to, Swift_Message $message = null)
*
* @param integer $count
*
* @return PHPUnit_Framework_TestCase $this
* @return TestCase $this
* @deprecated in favor of seeEmailCountEquals
*/
protected function seeEmailsSent($count)
Expand All @@ -259,7 +271,7 @@ protected function seeEmailsSent($count)
*
* @param integer $count
*
* @return PHPUnit_Framework_TestCase $this
* @return $this
*/
protected function seeEmailCountEquals($count)
{
Expand All @@ -276,7 +288,7 @@ protected function seeEmailCountEquals($count)
* @param string $subject
* @param Swift_Message|null $message
*
* @return PHPUnit_Framework_TestCase $this
* @return TestCase $this
* @deprecated in favor of seeEmailSubjectEquals
*/
protected function seeEmailSubject($subject, Swift_Message $message = null)
Expand All @@ -290,7 +302,7 @@ protected function seeEmailSubject($subject, Swift_Message $message = null)
* @param string $excerpt
* @param Swift_Message|null $message
*
* @return PHPUnit_Framework_TestCase $this
* @return $this
*/
protected function seeEmailSubjectContains($excerpt, Swift_Message $message = null)
{
Expand All @@ -307,7 +319,7 @@ protected function seeEmailSubjectContains($excerpt, Swift_Message $message = nu
* @param string $excerpt
* @param Swift_Message|null $message
*
* @return PHPUnit_Framework_TestCase $this
* @return $this
*/
protected function seeEmailSubjectDoesNotContain($excerpt, Swift_Message $message = null)
{
Expand All @@ -324,7 +336,7 @@ protected function seeEmailSubjectDoesNotContain($excerpt, Swift_Message $messag
* @param string $subject
* @param Swift_Message|null $message
*
* @return PHPUnit_Framework_TestCase $this
* @return $this
*/
protected function seeEmailSubjectEquals($subject, Swift_Message $message = null)
{
Expand All @@ -341,7 +353,7 @@ protected function seeEmailSubjectEquals($subject, Swift_Message $message = null
* @param string $recipient
* @param Swift_Message|null $message
*
* @return PHPUnit_Framework_TestCase $this
* @return $this
*/
protected function seeEmailTo($recipient, Swift_Message $message = null)
{
Expand All @@ -354,7 +366,7 @@ protected function seeEmailTo($recipient, Swift_Message $message = null)
/**
* Assert that no emails were sent.
*
* @return PHPUnit_Framework_TestCase $this
* @return $this
*/
protected function seeEmailWasNotSent()
{
Expand All @@ -368,7 +380,7 @@ protected function seeEmailWasNotSent()
/**
* Assert that at least one email was sent.
*
* @return PHPUnit_Framework_TestCase $this
* @return $this
*/
protected function seeEmailWasSent()
{
Expand Down
7 changes: 4 additions & 3 deletions tests/MailRecorderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Mockery;
use PHPUnit_Framework_Error;
use PHPUnit_Framework_TestCase;
use StdClass;
use Swift_Events_SendEvent;
use TypeError;
Expand Down Expand Up @@ -49,10 +48,12 @@ public function it_cannot_be_constructed_without_a_PHPUnit_Framework_TestCase()
/**
* @test
* @group unit
* @expectedException PHPUnit_Framework_Error
*/
public function it_cannot_be_constructed_with_class_other_than_a_PHPUnit_Framework_TestCase()
{
// TODO: Skipping this until resolving PhpUnit 6 vs. 7 support
$this->markTestSkipped();

if (class_exists(TypeError::class)) {
try {
new MailRecorder(new StdClass());
Expand All @@ -71,7 +72,7 @@ public function it_cannot_be_constructed_with_class_other_than_a_PHPUnit_Framewo
*/
public function it_records_the_message_on_the_test_by_calling_recordMail()
{
$test_mock = Mockery::mock(PHPUnit_Framework_TestCase::class);
$test_mock = Mockery::mock(TestCase::class);

$test_mock->shouldReceive('recordMail')
->once()
Expand Down
4 changes: 2 additions & 2 deletions tests/Stubs/MailTrackingStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

namespace Spinen\MailAssertions\Stubs;

use PHPUnit_Framework_TestCase;
use Spinen\MailAssertions\MailTracking;
use Spinen\MailAssertions\TestCase;

/**
* Class MailTrackingStub
*
* @package Spinen\MailAssertions\Stubs
*/
class MailTrackingStub extends PHPUnit_Framework_TestCase
class MailTrackingStub extends TestCase
{
use MailTracking;

Expand Down

0 comments on commit bbd7cfb

Please sign in to comment.