-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE: Requires Laravel v10 or above fix: phpstan ignore mocks fix: add missing package test: add test with attachments included ci: only run supported versions of php chore: clean up fix: change method to set attachment headers ci: change phpunit schema in runtime fix: fix typing fix: include phpunit and phpstan in composer.json ci: update workflow build: basic docker compose for local development feat: Laravel 10 compatability
- Loading branch information
1 parent
a1f3a95
commit 9084df7
Showing
5 changed files
with
159 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
services: | ||
php: | ||
image: php:8.3-fpm # Or any other version you want | ||
volumes: | ||
- ./:/var/www/html # Mount the current directory to the container | ||
working_dir: /var/www/html | ||
ports: | ||
- "8088:80" | ||
depends_on: | ||
- composer | ||
networks: | ||
- newsletter-driver-network | ||
|
||
composer: | ||
image: composer:latest | ||
volumes: | ||
- ./:/var/www/html # Same mount so composer can install dependencies | ||
working_dir: /var/www/html | ||
networks: | ||
- newsletter-driver-network | ||
entrypoint: ['composer'] | ||
|
||
networks: | ||
newsletter-driver-network: | ||
driver: bridge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace Lundalogik\NewsletterDriver\Tests\Unit; | ||
|
||
use Lundalogik\NewsletterDriver\Newsletter\SendTransactionMailBatchArgs; | ||
use Lundalogik\NewsletterDriver\Newsletter\TransactionMail; | ||
use PHPUnit\Framework\TestCase; | ||
use Lundalogik\NewsletterDriver\Transport\NewsletterTransport; | ||
use Mockery; | ||
use Spatie\TemporaryDirectory\Exceptions\PathAlreadyExists; | ||
use Spatie\TemporaryDirectory\TemporaryDirectory; | ||
use Symfony\Component\Mailer\Exception\TransportExceptionInterface; | ||
use Symfony\Component\Mime\Email; | ||
|
||
class NewsletterTransportTest extends TestCase | ||
{ | ||
|
||
/** | ||
* @throws PathAlreadyExists | ||
* @throws TransportExceptionInterface | ||
*/ | ||
public function test_it_can_send_full_email_with_attachments(): void | ||
{ | ||
$tempDir = (new TemporaryDirectory()) | ||
->deleteWhenDestroyed() | ||
->create(); | ||
|
||
$tmpPath = $tempDir->path('test.txt'); | ||
file_put_contents($tmpPath, 'this is a test'); | ||
|
||
$message = new Email(); | ||
$message->from('[email protected]') | ||
->to('[email protected]') | ||
->subject('Test from laravel-newsletter-driver') | ||
->html("<p>This is a test email from laravel-newsletter-driver</p>") | ||
->attachFromPath($tmpPath, 'test.txt'); | ||
|
||
$api = Mockery::mock(TransactionMail::class); | ||
|
||
/** @phpstan-ignore-next-line */ | ||
$api->shouldReceive('sendBatch') | ||
->once() | ||
->with(Mockery::on(function ($args) use ($message) { | ||
$this->assertInstanceOf(SendTransactionMailBatchArgs::class, $args); | ||
|
||
$batchArgs = $args->toArray(); | ||
$firstBatch = (object) $batchArgs['SendTransactionMailArgs'][0]; | ||
|
||
$this->assertEquals($firstBatch->RecipientEmail, $message->getTo()[0]->getAddress()); | ||
$this->assertEquals($firstBatch->RecipientName, $message->getTo()[0]->getName()); | ||
$this->assertEquals($firstBatch->FromEmail, $message->getFrom()[0]->getAddress()); | ||
$this->assertEquals($firstBatch->FromName, $message->getFrom()[0]->getName()); | ||
$this->assertEquals($firstBatch->Subject, $message->getSubject()); | ||
$this->assertNotEmpty($firstBatch->HtmlContent); | ||
|
||
$firstBatchAttachments = $batchArgs['BatchAttachments']; | ||
$this->assertEquals('test.txt', $firstBatchAttachments[0]['FileNameWithExtension']); | ||
|
||
return 1 === count($batchArgs['SendTransactionMailArgs']); | ||
}))->andReturn(); | ||
|
||
/** @phpstan-ignore-next-line */ | ||
(new NewsletterTransport($api))->send($message); | ||
} | ||
} |