Skip to content

Add Assertions for "Plus Sign Alias" Email Addresses #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ This will prevent any method name conflicts with core, your custom or other trai
\Astrotomic\PhpunitAssertions\EmailAssertions::assertValidStrict('gummibeer@astrotomic.info');
\Astrotomic\PhpunitAssertions\EmailAssertions::assertDomain('astrotomic.info', 'gummibeer@astrotomic.info');
\Astrotomic\PhpunitAssertions\EmailAssertions::assertLocalPart('gummibeer', 'gummibeer@astrotomic.info');
\Astrotomic\PhpunitAssertions\EmailAssertions::assertPlusMailbox('gummibeer', 'gummibeer+news@astrotomic.info');
\Astrotomic\PhpunitAssertions\EmailAssertions::assertPlusAlias('news', 'gummibeer+news@astrotomic.info');
```

### Geographic
Expand Down
16 changes: 16 additions & 0 deletions src/EmailAssertions.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,20 @@ public static function assertLocalPart(string $expected, $actual): void
[$localPart] = explode('@', $actual, 2);
PHPUnit::assertSame($expected, $localPart);
}

public static function assertPlusMailbox(string $expected, $actual): void
{
PHPUnit::assertIsString($actual);
[$localPart] = explode('@', $actual, 2);
[$mailbox] = explode('+', $localPart, 2);
PHPUnit::assertSame($expected, $mailbox);
}

public static function assertPlusAlias(string $expected, $actual): void
{
PHPUnit::assertIsString($actual);
[$localPart] = explode('@', $actual, 2);
[$mailbox, $alias] = explode('+', $localPart, 2);
PHPUnit::assertSame($expected, $alias);
}
}
26 changes: 26 additions & 0 deletions tests/EmailAssertionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,30 @@ public static function it_can_validate_local_part(): void

EmailAssertions::assertLocalPart($localPart, $localPart.'@email.com');
}

/**
* @test
* @dataProvider hundredTimes
*/
public static function it_can_validate_plus_mailbox(): void
{
$mailbox = self::randomString();
$alias = self::randomBool();
$email = $mailbox.'+'.$alias.'@email.com';

EmailAssertions::assertPlusMailbox($mailbox, $email);
}

/**
* @test
* @dataProvider hundredTimes
*/
public static function it_can_validate_plus_alias(): void
{
$mailbox = self::randomString();
$alias = self::randomBool();
$email = $mailbox.'+'.$alias.'@email.com';

EmailAssertions::assertPlusAlias($alias, $email);
}
}