From 4d446bf971d0e25f44c52320b33e60acefb4657d Mon Sep 17 00:00:00 2001 From: "Issei.M" Date: Thu, 4 Aug 2016 05:42:12 +0900 Subject: [PATCH] NoRFCWarningsValidation now has an InvalidEmail instance if invalid email is passed (#126) * NoRFCWarningsValidation now has an InvalidEmail instance if invalid email is passed * fix mentioned point --- .../Validation/Error/RFCWarnings.php | 11 ++++++ .../Validation/NoRFCWarningsValidation.php | 30 +++++++++++++++- .../NoRFCWarningsValidationTest.php | 35 +++++++++++++++++++ .../NoWarningsRFCValidationTest.php | 23 ------------ 4 files changed, 75 insertions(+), 24 deletions(-) create mode 100644 EmailValidator/Validation/Error/RFCWarnings.php create mode 100644 Tests/EmailValidator/Validation/NoRFCWarningsValidationTest.php delete mode 100644 Tests/EmailValidator/Validation/NoWarningsRFCValidationTest.php diff --git a/EmailValidator/Validation/Error/RFCWarnings.php b/EmailValidator/Validation/Error/RFCWarnings.php new file mode 100644 index 0000000..7f2256d --- /dev/null +++ b/EmailValidator/Validation/Error/RFCWarnings.php @@ -0,0 +1,11 @@ +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(); } } diff --git a/Tests/EmailValidator/Validation/NoRFCWarningsValidationTest.php b/Tests/EmailValidator/Validation/NoRFCWarningsValidationTest.php new file mode 100644 index 0000000..e200b94 --- /dev/null +++ b/Tests/EmailValidator/Validation/NoRFCWarningsValidationTest.php @@ -0,0 +1,35 @@ +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('example@example.com', new EmailLexer())); + $this->assertNull($validation->getError()); + } +} diff --git a/Tests/EmailValidator/Validation/NoWarningsRFCValidationTest.php b/Tests/EmailValidator/Validation/NoWarningsRFCValidationTest.php deleted file mode 100644 index acff57c..0000000 --- a/Tests/EmailValidator/Validation/NoWarningsRFCValidationTest.php +++ /dev/null @@ -1,23 +0,0 @@ -assertFalse($validation->isValid('examp"l"e@example.com', new EmailLexer())); - } - - public function testEmailWithoutWarningsIsValid() - { - $validation = new NoRFCWarningsValidation(); - - $this->assertTrue($validation->isValid('example@example.com', new EmailLexer())); - } -}