-
-
Notifications
You must be signed in to change notification settings - Fork 220
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
NoRFCWarningsValidation now has an InvalidEmail instance if invalid email is passed #126
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Egulias\EmailValidator\Validation\Error; | ||
|
||
use Egulias\EmailValidator\Exception\InvalidEmail; | ||
|
||
/** | ||
* @author Issei Murasawa <[email protected]> | ||
*/ | ||
class RFCWarnings extends InvalidEmail | ||
{ | ||
const code = 997; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please change it to uppercase |
||
const REASON = 'The email has no error with RFC, but some warnings.'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,39 @@ | |
namespace Egulias\EmailValidator\Validation; | ||
|
||
use Egulias\EmailValidator\EmailLexer; | ||
use Egulias\EmailValidator\Exception\InvalidEmail; | ||
use Egulias\EmailValidator\Validation\Error\RFCWarnings; | ||
|
||
class NoRFCWarningsValidation extends RFCValidation | ||
{ | ||
/** | ||
* @var InvalidEmail | ||
*/ | ||
private $error; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function isValid($email, EmailLexer $emailLexer) | ||
{ | ||
return parent::isValid($email, $emailLexer) && empty($this->getWarnings()); | ||
if (!parent::isValid($email, $emailLexer)) { | ||
return false; | ||
} | ||
|
||
if (empty($this->getWarnings())) { | ||
return true; | ||
} | ||
|
||
$this->error = new RFCWarnings(); | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getError() | ||
{ | ||
return $this->error ?: parent::getError(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great :) (just deleted a comment about this ;) ) |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Egulias\Tests\EmailValidator\Validation; | ||
|
||
use Egulias\EmailValidator\EmailLexer; | ||
use Egulias\EmailValidator\Exception\NoDomainPart; | ||
use Egulias\EmailValidator\Validation\Error\RFCWarnings; | ||
use Egulias\EmailValidator\Validation\NoRFCWarningsValidation; | ||
|
||
class NoRFCWarningsValidationTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testInvalidEmailIsInvalid() | ||
{ | ||
$validation = new NoRFCWarningsValidation(); | ||
|
||
$this->assertFalse($validation->isValid('non-email-string', new EmailLexer())); | ||
$this->assertInstanceOf(NoDomainPart::class, $validation->getError()); | ||
} | ||
|
||
public function testEmailWithWarningsIsInvalid() | ||
{ | ||
$validation = new NoRFCWarningsValidation(); | ||
|
||
$this->assertFalse($validation->isValid(str_repeat('x', 254).'@example.com', new EmailLexer())); // too long email | ||
$this->assertInstanceOf(RFCWarnings::class, $validation->getError()); | ||
} | ||
|
||
public function testEmailWithoutWarningsIsValid() | ||
{ | ||
$validation = new NoRFCWarningsValidation(); | ||
|
||
$this->assertTrue($validation->isValid('[email protected]', new EmailLexer())); | ||
$this->assertNull($validation->getError()); | ||
} | ||
} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove, we have git for this ;)