-
-
Notifications
You must be signed in to change notification settings - Fork 225
Reimplement DNSCheckValidation #250
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
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3c0d187
Reimplement DNSCheckValidation to utilise get_dns_record and extend s…
BenHarris 1e67a37
Change valid email tests to use github.com instead of example.com as …
BenHarris 02e3071
Tweak to pass CI psalm issue
BenHarris 0eb972f
Encapsulate dns check code. Simplify local and reserved domain checks…
BenHarris 6b9e30e
Set PHPDoc return type
BenHarris a70fc5f
Set PHPDoc return type
BenHarris ee3b9b3
Fix Docblock
BenHarris 3fbc3a0
Fix Docblock
BenHarris cddaaf3
Use strict comparisons
BenHarris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,9 @@ | ||
| <?php | ||
|
|
||
| namespace Egulias\EmailValidator\Exception; | ||
|
|
||
| class DomainAcceptsNoMail extends InvalidEmail | ||
| { | ||
| const CODE = 154; | ||
| const REASON = 'Domain accepts no mail (Null MX, RFC7505)'; | ||
| } | ||
This file contains hidden or 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,9 @@ | ||
| <?php | ||
|
|
||
| namespace Egulias\EmailValidator\Exception; | ||
|
|
||
| class LocalOrReservedDomain extends InvalidEmail | ||
| { | ||
| const CODE = 153; | ||
| const REASON = 'Local, mDNS or reserved domain (RFC2606, RFC6762)'; | ||
egulias marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -4,6 +4,8 @@ | |
|
|
||
| use Egulias\EmailValidator\EmailLexer; | ||
| use Egulias\EmailValidator\Exception\NoDNSRecord; | ||
| use Egulias\EmailValidator\Exception\LocalOrReservedDomain; | ||
| use Egulias\EmailValidator\Exception\DomainAcceptsNoMail; | ||
| use Egulias\EmailValidator\Validation\DNSCheckValidation; | ||
| use Egulias\EmailValidator\Warning\NoDNSMXRecord; | ||
| use PHPUnit\Framework\TestCase; | ||
|
|
@@ -14,22 +16,44 @@ public function validEmailsProvider() | |
| { | ||
| return [ | ||
| // dot-atom | ||
| ['Abc@example.com'], | ||
| ['ABC@EXAMPLE.COM'], | ||
| ['Abc.123@example.com'], | ||
| ['user+mailbox/department=shipping@example.com'], | ||
| ['!#$%&\'*+-/=?^_`.{|}~@example.com'], | ||
| ['Abc@ietf.org'], | ||
| ['ABC@ietf.org'], | ||
| ['Abc.123@ietf.org'], | ||
| ['user+mailbox/department=shipping@ietf.org'], | ||
| ['!#$%&\'*+-/=?^_`.{|}~@ietf.org'], | ||
|
|
||
| // quoted string | ||
| ['"Abc@def"@example.com'], | ||
| ['"Fred\ Bloggs"@example.com'], | ||
| ['"Joe.\\Blow"@example.com'], | ||
| ['"Abc@def"@ietf.org'], | ||
| ['"Fred\ Bloggs"@ietf.org'], | ||
| ['"Joe.\\Blow"@ietf.org'], | ||
|
|
||
| // unicide | ||
| ['ñandu.cl'], | ||
| ]; | ||
| } | ||
|
|
||
| public function localOrReservedEmailsProvider() | ||
| { | ||
| return [ | ||
| // Reserved Top Level DNS Names | ||
| ['test'], | ||
| ['example'], | ||
| ['invalid'], | ||
| ['localhost'], | ||
|
|
||
| // mDNS | ||
| ['local'], | ||
|
|
||
| // Private DNS Namespaces | ||
| ['intranet'], | ||
| ['internal'], | ||
| ['private'], | ||
| ['corp'], | ||
| ['home'], | ||
| ['lan'], | ||
| ]; | ||
| } | ||
|
|
||
| /** | ||
| * @dataProvider validEmailsProvider | ||
| */ | ||
|
|
@@ -45,13 +69,35 @@ public function testInvalidDNS() | |
| $this->assertFalse($validation->isValid("[email protected]", new EmailLexer())); | ||
| } | ||
|
|
||
| /** | ||
| * @dataProvider localOrReservedEmailsProvider | ||
| */ | ||
| public function testLocalOrReservedDomainError($localOrReservedEmails) | ||
| { | ||
| $validation = new DNSCheckValidation(); | ||
| $expectedError = new LocalOrReservedDomain(); | ||
| $validation->isValid($localOrReservedEmails, new EmailLexer()); | ||
| $this->assertEquals($expectedError, $validation->getError()); | ||
| } | ||
|
|
||
| public function testDomainAcceptsNoMailError() | ||
| { | ||
| $validation = new DNSCheckValidation(); | ||
| $expectedError = new DomainAcceptsNoMail(); | ||
| $isValidResult = $validation->isValid("[email protected]", new EmailLexer()); | ||
| $this->assertEquals($expectedError, $validation->getError()); | ||
| $this->assertFalse($isValidResult); | ||
| } | ||
|
|
||
| /* | ||
| public function testDNSWarnings() | ||
| { | ||
| $validation = new DNSCheckValidation(); | ||
| $expectedWarnings = [NoDNSMXRecord::CODE => new NoDNSMXRecord()]; | ||
| $validation->isValid("[email protected]", new EmailLexer()); | ||
| $this->assertEquals($expectedWarnings, $validation->getWarnings()); | ||
| } | ||
| */ | ||
|
|
||
| public function testNoDNSError() | ||
BenHarris marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
|
|
@@ -60,4 +106,4 @@ public function testNoDNSError() | |
| $validation->isValid("[email protected]", new EmailLexer()); | ||
| $this->assertEquals($expectedError, $validation->getError()); | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.