Skip to content

Commit

Permalink
Merge pull request #32 from PhantPHP/Email-recipients
Browse files Browse the repository at this point in the history
Email to recipents list
  • Loading branch information
lennyrouanet authored Mar 25, 2024
2 parents b2bfde5 + a8e13b6 commit acd4253
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 18 deletions.
10 changes: 6 additions & 4 deletions component/Web/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ final public function __construct(
public string $messageTxt,
public string $messageHtml,
public EmailAddressAndName $from,
public EmailAddressAndName $to,
public EmailAddressAndNameList $to,
public ?EmailAddressAndName $replyTo = null,
public ?EmailAttachmentList $attachmentList = null
) {
Expand All @@ -40,9 +40,11 @@ public static function make(
$fromEmailAddress,
$fromName
),
EmailAddressAndName::make(
$toEmailAddress,
$toName
(new EmailAddressAndNameList())->add(
EmailAddressAndName::make(
$toEmailAddress,
$toName
)
),
$replyToEmailAddress ? EmailAddressAndName::make(
$replyToEmailAddress,
Expand Down
16 changes: 16 additions & 0 deletions component/Web/EmailAddressAndNameList.php
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\EmailAddressAndName;

class EmailAddressAndNameList extends \Phant\DataStructure\Abstract\Collection
{
final public function add(
EmailAddressAndName $emailAddressAndName
): self {
return $this->addItem($emailAddressAndName);
}
}
35 changes: 35 additions & 0 deletions test/Web/EmailAddressAndNameListTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace Test\Web;

use Phant\DataStructure\Web\{
EmailAddress,
EmailAddressAndName,
EmailAddressAndNameList,
};

final class EmailAddressAndNameListTest extends \PHPUnit\Framework\TestCase
{
protected EmailAddressAndNameList $fixture;

public function setUp(): void
{
$this->fixture = new EmailAddressAndNameList();
}

public function testAdd(): void
{
$this->assertEquals(0, $this->fixture->getNbItems());

$this->fixture->add(
new EmailAddressAndName(
new EmailAddress('[email protected]'),
'John DOE'
)
);

$this->assertEquals(1, $this->fixture->getNbItems());
}
}
2 changes: 0 additions & 2 deletions test/Web/EmailAddressAndNameTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
use Phant\DataStructure\Web\EmailAddressAndName;
use Phant\DataStructure\Web\EmailAddress;

use Phant\Error\NotCompliant;

final class EmailAddressAndNameTest extends \PHPUnit\Framework\TestCase
{
public function testInterface(): void
Expand Down
30 changes: 18 additions & 12 deletions test/Web/EmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
Email,
EmailAddress,
EmailAddressAndName,
EmailAddressAndNameList,
EmailAttachment,
EmailAttachmentList,
};
Expand Down Expand Up @@ -39,9 +40,11 @@ public function testInterface(): void
new EmailAddress('[email protected]'),
'Acme'
),
new EmailAddressAndName(
new EmailAddress('[email protected]'),
'John DOE'
(new EmailAddressAndNameList())->add(
new EmailAddressAndName(
new EmailAddress('[email protected]'),
'John DOE'
)
),
new EmailAddressAndName(
new EmailAddress('[email protected]'),
Expand All @@ -65,9 +68,10 @@ public function testInterface(): void
$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->assertInstanceOf(EmailAddressAndNameList::class, $email->to);
$to = $email->to->itemsIterator()->current();
$this->assertEquals('[email protected]', (string)$to->emailAddress);
$this->assertEquals('John DOE', $to->name);

$this->assertIsObject($email->replyTo);
$this->assertInstanceOf(EmailAddressAndName::class, $email->replyTo);
Expand Down Expand Up @@ -110,9 +114,10 @@ public function testMake(): void
$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->assertInstanceOf(EmailAddressAndNameList::class, $email->to);
$to = $email->to->itemsIterator()->current();
$this->assertEquals('[email protected]', (string)$to->emailAddress);
$this->assertEquals('John DOE', $to->name);

$this->assertIsObject($email->replyTo);
$this->assertInstanceOf(EmailAddressAndName::class, $email->replyTo);
Expand Down Expand Up @@ -152,9 +157,10 @@ public function testMakeBasic(): void
$this->assertNull($email->from->name);

$this->assertIsObject($email->to);
$this->assertInstanceOf(EmailAddressAndName::class, $email->to);
$this->assertEquals('[email protected]', (string)$email->to->emailAddress);
$this->assertNull($email->to->name);
$this->assertInstanceOf(EmailAddressAndNameList::class, $email->to);
$to = $email->to->itemsIterator()->current();
$this->assertEquals('[email protected]', (string)$to->emailAddress);
$this->assertNull($to->name);

$this->assertNull($email->replyTo);

Expand Down

0 comments on commit acd4253

Please sign in to comment.