Skip to content

Commit

Permalink
Test response event
Browse files Browse the repository at this point in the history
  • Loading branch information
hkdobrev committed Jan 23, 2015
1 parent 086287e commit c0f2c3a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
16 changes: 16 additions & 0 deletions tests/src/Swift/PostmarkTransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@ public function test_newInstance()
$this->assertEquals('token', $postmarkTransport->api()->token());
}

/**
* @covers Openbuildings\Postmark\Swift_PostmarkTransport::newInstance
*/
public function test_newInstance_with_token()
{
$postmarkTransport = Swift_PostmarkTransport::newInstance('POSTMARK_API_TEST');
$this->assertInstanceOf(
'Openbuildings\Postmark\Swift_PostmarkTransport',
$postmarkTransport
);
$this->assertInstanceOf('Openbuildings\Postmark\Api', $postmarkTransport->api());

$postmarkTransport = Swift_PostmarkTransport::newInstance('token');
$this->assertEquals('token', $postmarkTransport->api()->token());
}

/**
* @covers Openbuildings\Postmark\Swift_PostmarkTransport::__construct
*/
Expand Down
39 changes: 36 additions & 3 deletions tests/src/Swift/Transport/PostmarkTransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Swift_Attachment;
use PHPUnit_Framework_TestCase;
use Swift_DependencyContainer;
use Swift_Events_ResponseEvent;
use Swift_Events_SimpleEventDispatcher;

/**
Expand Down Expand Up @@ -105,11 +106,40 @@ public function test_convert_email_array(array $emails, $expected_converted_emai
*/
public function test_send()
{
$transport = Swift_PostmarkTransport::newInstance('POSTMARK_API_TEST');
$this->assertInstanceOf('Openbuildings\Postmark\Api', $transport->api());
$event_dispatcher_mock = $this->getMock(
'Swift_Events_SimpleEventDispatcher',
array(
'createResponseEvent',
'dispatchEvent'
)
);

$transport = new Swift_Transport_PostmarkTransport(
$event_dispatcher_mock
);

$response_event = new Swift_Events_ResponseEvent($transport, array(
'MessageID' => '123456',
), true);

$event_dispatcher_mock
->expects($this->once())
->method('createResponseEvent')
->with(
$transport,
'123456',
true
)
->will($this->returnValue($response_event));

$event_dispatcher_mock
->expects($this->at(3))
->method('dispatchEvent')
->with($response_event, 'responseReceived');

$api = $this->getMock('Openbuildings\Postmark\Api', array(), array('POSTMARK_API_TEST'));
$transport->api($api);

$mailer = Swift_Mailer::newInstance($transport);

$api->expects($this->at(0))
Expand All @@ -123,7 +153,10 @@ public function test_send()
'TextBody' => 'Test Email',
)
)
);
)
->will($this->returnValue(array(
'MessageID' => '123456',
)));

$api->expects($this->at(1))
->method('send')
Expand Down

0 comments on commit c0f2c3a

Please sign in to comment.