Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gam6itko committed Jun 8, 2020
1 parent 9a65431 commit 5925cda
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 9 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# SparkPost transport for Symfony Mailer
[![Build Status](https://travis-ci.com/gam6itko/sparkpost-mailer.svg?branch=master)](https://travis-ci.com/gam6itko/sparkpost-mailer)
[![Coverage Status](https://coveralls.io/repos/github/gam6itko/sparkpost-mailer/badge.svg?branch=master)](https://coveralls.io/github/gam6itko/sparkpost-mailer?branch=master)

## install

Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
"symfony/mailer": "^4.4|^5.0"
},
"require-dev": {
"dg/bypass-finals": "^1.2",
"php-coveralls/php-coveralls": "^2.2",
"phpunit/phpunit": "^7.4||^8.0||^9.0",
"symfony/http-client": "^4.4|^5.0",
"php-coveralls/php-coveralls": "^2.2"
"symfony/http-client": "^4.4|^5.0"
},
"autoload": {
"psr-4": {"Gam6itko\\Symfony\\Mailer\\SparkPost\\": "src"}
Expand Down
7 changes: 1 addition & 6 deletions src/Transport/SparkPostApiTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct(string $key, HttpClientInterface $client = null, Eve

public function __toString(): string
{
return sprintf('sparkpost+api://%s', $this->getEndpoint());
return 'sparkpost+api://';
}

protected function doSendApi(SentMessage $sentMessage, Email $email, Envelope $envelope): ResponseInterface
Expand Down Expand Up @@ -60,11 +60,6 @@ protected function doSendApi(SentMessage $sentMessage, Email $email, Envelope $e
]);
}

private function getEndpoint(): ?string
{
return $this->host.($this->port ? ':'.$this->port : '');
}

private function buildRecipients(Envelope $envelope): array
{
$result = [];
Expand Down
14 changes: 14 additions & 0 deletions tests/EventListener/SinkEnvelopeListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Gam6itko\Symfony\Mailer\SparkPost\Test\EventListener;

use DG\BypassFinals;
use Gam6itko\Symfony\Mailer\SparkPost\EventListener\SinkEnvelopeListener;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Mailer\Envelope;
Expand Down Expand Up @@ -33,4 +34,17 @@ public function testSinkEmail()
return $address->getAddress();
}, $envelope->getRecipients()));
}

public function testNoPrefix()
{
BypassFinals::enable();

$messageEvent = $this->createMock(MessageEvent::class);
$messageEvent
->expects(self::never())
->method('getEnvelope');

$listener = new SinkEnvelopeListener('');
$listener->onMessage($messageEvent);
}
}
24 changes: 24 additions & 0 deletions tests/Mime/ABTestEmailTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php declare(strict_types=1);

namespace Gam6itko\Symfony\Mailer\SparkPost\Test\Mime;

use Gam6itko\Symfony\Mailer\SparkPost\Mime\ABTestEmail;
use PHPUnit\Framework\TestCase;

/**
* @coversDefaultClass \Gam6itko\Symfony\Mailer\SparkPost\Mime\ABTestEmail
*/
class ABTestEmailTest extends TestCase
{
public function test()
{
$email = new ABTestEmail('id');
self::assertEquals(
[
'ab_test_id' => 'id',
],
$email->getContent()
);
self::assertEmpty($email->getSubstitutionData());
}
}
24 changes: 24 additions & 0 deletions tests/Mime/TemplateEmailTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php declare(strict_types=1);

namespace Gam6itko\Symfony\Mailer\SparkPost\Test\Mime;

use Gam6itko\Symfony\Mailer\SparkPost\Mime\TemplateEmail;
use PHPUnit\Framework\TestCase;

/**
* @coversDefaultClass \Gam6itko\Symfony\Mailer\SparkPost\Mime\TemplateEmail
*/
class TemplateEmailTest extends TestCase
{
public function test()
{
$email = new TemplateEmail('template', true);
self::assertEquals(
[
'template_id' => 'template',
'use_draft_template' => true,
],
$email->getContent()
);
}
}
9 changes: 8 additions & 1 deletion tests/Transport/SparkPostApiTransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public function dataSend()
];
}

public function testTruncateAttachemtData()
public function testTruncateAttachemntData()
{
$message = (new Email())
->from('[email protected]')
Expand All @@ -225,4 +225,11 @@ public function testTruncateAttachemtData()
$transport = new SparkPostApiTransport('api-key', $client, null, $logger);
$transport->send($message, $envelope);
}

public function testToString()
{
$client = $this->createMock(HttpClientInterface::class);
$transport = new SparkPostApiTransport('api-key', $client);
self::assertSame('sparkpost+api://', (string) $transport);
}
}

0 comments on commit 5925cda

Please sign in to comment.