-
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.
- Loading branch information
1 parent
37ee70d
commit dda9946
Showing
6 changed files
with
137 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Phant\DataStructure\Web; | ||
|
||
class EmailAttachment | ||
{ | ||
final public function __construct( | ||
public string $name, | ||
public string $content, | ||
public string $type | ||
) { | ||
} | ||
} |
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,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Phant\DataStructure\Web; | ||
|
||
use Phant\DataStructure\Web\EmailAttachment; | ||
|
||
class EmailAttachmentList extends \Phant\DataStructure\Abstract\Collection | ||
{ | ||
final public function add( | ||
EmailAttachment $attachment | ||
): self { | ||
return $this->addItem($attachment); | ||
} | ||
} |
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,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Test\Web; | ||
|
||
use Phant\DataStructure\Web\{ | ||
EmailAttachment, | ||
EmailAttachmentList, | ||
}; | ||
use Test\Web\EmailAttachmentTest; | ||
|
||
final class EmailAttachmentListTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
protected EmailAttachmentList $fixture; | ||
|
||
public function setUp(): void | ||
{ | ||
$this->fixture = new EmailAttachmentList(); | ||
} | ||
|
||
public function testAdd(): void | ||
{ | ||
$this->assertEquals(0, $this->fixture->getNbItems()); | ||
|
||
$this->fixture->add( | ||
new EmailAttachment( | ||
'file.pdf', | ||
EmailAttachmentTest::Content, | ||
'application/pdf' | ||
) | ||
); | ||
|
||
$this->assertEquals(1, $this->fixture->getNbItems()); | ||
} | ||
} |
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,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Test\Web; | ||
|
||
use Phant\DataStructure\Web\EmailAttachment; | ||
|
||
final class EmailAttachmentTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
public const Content = 'JVBERi0xLjcNCiXi48/TDQozIDAgb2JqDQo8PA0KL0xpbmVhcml6ZWQgMQ0KL0wgMTYzMA0KL0ggWyA2MjAgMTIyIF0NCi9PIDUNCi9FIDEyMTcNCi9OIDENCi9UIDE0NDQNCj4+DQplbmRvYmoNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICANCnhyZWYNCjMgNQ0KMDAwMDAwMDAxNyAwMDAwMCBuDQowMDAwMDAwNTY1IDAwMDAwIG4NCjAwMDAwMDA3NDIgMDAwMDAgbg0KMDAwMDAwMDg5NCAwMDAwMCBuDQowMDAwMDAwNjIwIDAwMDAwIG4NCnRyYWlsZXINCjw8DQovU2l6ZSA4DQovUHJldiAxNDM0DQovSW5mbyAyIDAgUg0KL1Jvb3QgNCAwIFINCi9JRCBbPGQyMjc5OTNkMzg3N2EwZDA5MTgzYWRhN2FjZWFkZDEwPjxkMjI3OTkzZDM4NzdhMGQwOTE4M2FkYTdhY2VhZGQxMD5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1R5cGUgL1BhZ2VzDQovS2lkcyBbIDUgMCBSIF0NCi9Db3VudCAxDQo+Pg0KZW5kb2JqDQoyIDAgb2JqDQo8PA0KL01vZERhdGUgKEQ6MjAyMzEyMDQwODU2MDIrMDEnMDAnKQ0KL1Byb2R1Y2VyDQooMy1IZWlnaHRzXChUTVwpIFBERiBPcHRpbWl6YXRpb24gU2hlbGwgNS45LjEuNSBcKGh0dHA6Ly93d3cucGRmLXRvb2xzLmNvbVwpKQ0KPj4NCmVuZG9iag0KeHJlZg0KMCAzDQowMDAwMDAwMDAwIDY1NTM1IGYNCjAwMDAwMDEyMTcgMDAwMDAgbg0KMDAwMDAwMTI4MyAwMDAwMCBuDQp0cmFpbGVyDQo8PA0KL1NpemUgMw0KL0lEIFs8ZDIyNzk5M2QzODc3YTBkMDkxODNhZGE3YWNlYWRkMTA+PGQyMjc5OTNkMzg3N2EwZDA5MTgzYWRhN2FjZWFkZDEwPl0NCj4+DQpzdGFydHhyZWYNCjE3OA0KJSVFT0YNCg=='; | ||
|
||
public function testInterface(): void | ||
{ | ||
$email = new EmailAttachment( | ||
'file.pdf', | ||
self::Content, | ||
'application/pdf' | ||
); | ||
|
||
$this->assertIsString($email->name); | ||
$this->assertEquals('file.pdf', $email->name); | ||
|
||
$this->assertIsString($email->content); | ||
$this->assertEquals(self::Content, $email->content); | ||
|
||
$this->assertIsString($email->type); | ||
$this->assertEquals('application/pdf', $email->type); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -8,12 +8,27 @@ | |
Email, | ||
EmailAddress, | ||
EmailAddressAndName, | ||
EmailAttachment, | ||
EmailAttachmentList, | ||
}; | ||
|
||
use Phant\Error\NotCompliant; | ||
use Test\Web\EmailAttachmentTest; | ||
|
||
final class EmailTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
protected EmailAttachmentList $attachmentList; | ||
|
||
public function setUp(): void | ||
{ | ||
$this->attachmentList = (new EmailAttachmentList()) | ||
->add( | ||
new EmailAttachment( | ||
'file.pdf', | ||
EmailAttachmentTest::Content, | ||
'application/pdf' | ||
) | ||
); | ||
} | ||
|
||
public function testInterface(): void | ||
{ | ||
$email = new Email( | ||
|
@@ -31,7 +46,8 @@ public function testInterface(): void | |
new EmailAddressAndName( | ||
new EmailAddress('[email protected]'), | ||
'No reply' | ||
) | ||
), | ||
$this->attachmentList | ||
); | ||
|
||
$this->assertIsString($email->subject); | ||
|
@@ -44,16 +60,22 @@ public function testInterface(): void | |
$this->assertEquals('<p>Message</p>', $email->messageHtml); | ||
|
||
$this->assertIsObject($email->from); | ||
$this->assertInstanceOf(EmailAddressAndName::class, $email->from); | ||
$this->assertEquals('[email protected]', (string)$email->from->emailAddress); | ||
$this->assertEquals('Acme', $email->from->name); | ||
|
||
$this->assertIsObject($email->to); | ||
$this->assertInstanceOf(EmailAddressAndName::class, $email->to); | ||
$this->assertEquals('[email protected]', (string)$email->to->emailAddress); | ||
$this->assertEquals('John DOE', $email->to->name); | ||
|
||
$this->assertIsObject($email->replyTo); | ||
$this->assertInstanceOf(EmailAddressAndName::class, $email->replyTo); | ||
$this->assertEquals('[email protected]', (string)$email->replyTo->emailAddress); | ||
$this->assertEquals('No reply', $email->replyTo->name); | ||
|
||
$this->assertIsObject($email->attachmentList); | ||
$this->assertInstanceOf(EmailAttachmentList::class, $email->attachmentList); | ||
} | ||
|
||
public function testMake(): void | ||
|
@@ -67,7 +89,8 @@ public function testMake(): void | |
'[email protected]', | ||
'John DOE', | ||
'[email protected]', | ||
'No reply' | ||
'No reply', | ||
$this->attachmentList | ||
); | ||
|
||
$this->assertInstanceOf(Email::class, $email); | ||
|
@@ -82,15 +105,21 @@ public function testMake(): void | |
$this->assertEquals('<p>Message</p>', $email->messageHtml); | ||
|
||
$this->assertIsObject($email->from); | ||
$this->assertInstanceOf(EmailAddressAndName::class, $email->from); | ||
$this->assertEquals('[email protected]', (string)$email->from->emailAddress); | ||
$this->assertEquals('Acme', $email->from->name); | ||
|
||
$this->assertIsObject($email->to); | ||
$this->assertInstanceOf(EmailAddressAndName::class, $email->to); | ||
$this->assertEquals('[email protected]', (string)$email->to->emailAddress); | ||
$this->assertEquals('John DOE', $email->to->name); | ||
|
||
$this->assertIsObject($email->replyTo); | ||
$this->assertInstanceOf(EmailAddressAndName::class, $email->replyTo); | ||
$this->assertEquals('[email protected]', (string)$email->replyTo->emailAddress); | ||
$this->assertEquals('No reply', $email->replyTo->name); | ||
|
||
$this->assertIsObject($email->attachmentList); | ||
$this->assertInstanceOf(EmailAttachmentList::class, $email->attachmentList); | ||
} | ||
} |