-
-
Notifications
You must be signed in to change notification settings - Fork 58
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
Showing
8 changed files
with
448 additions
and
21 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 |
---|---|---|
|
@@ -19,12 +19,17 @@ class AddressPartTest extends TestCase | |
{ | ||
// @phpstan-ignore-next-line | ||
private $mb; | ||
private $hpf; | ||
private $logger; | ||
|
||
protected function setUp() : void | ||
{ | ||
$this->logger = \mmpGetTestLogger(); | ||
$this->mb = new MbWrapper(); | ||
$this->hpf = $this->getMockBuilder(HeaderPartFactory::class) | ||
->setConstructorArgs([$this->logger, $this->mb]) | ||
->setMethods() | ||
->getMock(); | ||
} | ||
|
||
private function newAddressPart($nameParts, $valueParts) | ||
|
@@ -40,6 +45,22 @@ private function getTokenMock(string $name) : Token | |
->getMock(); | ||
} | ||
|
||
private function getQuotedMock(string $name) : QuotedLiteralPart | ||
{ | ||
return $this->getMockBuilder(QuotedLiteralPart::class) | ||
->setConstructorArgs([$this->logger, $this->mb, [$this->getTokenMock($name)]]) | ||
->setMethods() | ||
->getMock(); | ||
} | ||
|
||
private function getCommentMock(string $name) : CommentPart | ||
{ | ||
return $this->getMockBuilder(CommentPart::class) | ||
->setConstructorArgs([$this->logger, $this->mb, $this->hpf, [$this->getTokenMock($name)]]) | ||
->setMethods() | ||
->getMock(); | ||
} | ||
|
||
public function testNameEmail() : void | ||
{ | ||
$name = 'Julius Caeser'; | ||
|
@@ -49,12 +70,36 @@ public function testNameEmail() : void | |
$this->assertEquals($email, $part->getEmail()); | ||
} | ||
|
||
public function testEmailWithQuotedParts() : void | ||
{ | ||
$email = 'gaius" julius "[email protected]'; | ||
$part = $this->newAddressPart([], [$this->getTokenMock('gaius '), $this->getQuotedMock(' julius '), $this->getTokenMock(' caesa [email protected]')]); | ||
$this->assertEquals($email, $part->getEmail()); | ||
} | ||
|
||
public function testEmailWithCommentsAndQuotedParts() : void | ||
{ | ||
$email = 'gaius"julius"[email protected]'; | ||
$part = $this->newAddressPart([], [ | ||
$this->getTokenMock('gaius '), | ||
$this->getQuotedMock('julius'), | ||
$this->getTokenMock('caesar'), | ||
$this->getCommentMock('emperor, innit'), | ||
$this->getTokenMock('@altavista.com') | ||
]); | ||
$this->assertEquals($email, $part->getEmail()); | ||
$comments = $part->getComments(); | ||
$this->assertNotEmpty($comments); | ||
$this->assertCount(1, $comments); | ||
$this->assertEquals('emperor, innit', $comments[0]->getComment()); | ||
} | ||
|
||
public function testValidation() : void | ||
{ | ||
$part = $this->newAddressPart([], []); | ||
$errs = $part->getErrors(true, LogLevel::ERROR); | ||
$this->assertCount(1, $errs); | ||
$this->assertEquals('Address doesn\'t contain an email address', $errs[0]->getMessage()); | ||
$this->assertNotEmpty($errs[0]->getMessage()); | ||
$this->assertEquals(LogLevel::ERROR, $errs[0]->getPsrLevel()); | ||
} | ||
} |
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
Oops, something went wrong.