Compare commits

..

18 Commits

Author SHA1 Message Date
Gabriel Caruso 1bec00a100 Use PHPUnit\Framework\TestCase instead of PHPUnit_Framework_TestCase (#155)
* Use PHPUnit\Framework\TestCase instead of PHPUnit_Framework_TestCase

* Use installed PHPUnit version not global
2017-11-16 00:40:40 +01:00
Santiago Castro 3abad65421 Fix broken Markdown headings (#149) 2017-04-18 23:06:35 +02:00
Dany Maillard 3fdfa261ad Remove duplicat < and > char value (#147) 2017-04-13 10:55:46 +02:00
Christian Flothmann 14ca3785c1 improve feedback on missing Intl extension (#143) 2017-03-02 11:09:01 +01:00
Eduardo Gulias Davis bc31baa11e Le shadow master (#139)
* Compatibility with RFC 2181

According to RFC2181, every DNS query needs to have a . at the end of
the name record you are requesting.

This will show that that name record is the root of the domain you are
asking
In some cases, when the . is missing, the hostname of the server the
code is running on will be appended to the name record when
checkdnsrr() is being executed and this will in turn return a false
positive when there is a wildcard DNS record for the root domain of the
hostname of the server.

* Test deprecation warnings removed
2017-01-30 23:07:36 +01:00
Simone c0c888ae10 removes trailing spaces (#136) 2017-01-25 22:45:20 +01:00
gjenjoying 181a2fc726 update readme (#135)
* update readme

use Egulias\EmailValidator\Validation\RFCValidation  is required.
2016-12-15 20:18:15 +01:00
Alf Eaton a1e85fa9fb Fix NoRFCWarningsValidation name in README (#134) 2016-11-10 20:04:43 +01:00
BradChesney79 7ff8caaae5 Update composer.json to use the right extension string (#127)
By using
"ext-intl": "*"
in the require block, the suggestion will be hidden if it is already available. ext/php-intl has few google search results and will confuse less knowledgeable users.
2016-08-16 00:24:12 +02:00
Eduardo Gulias Davis 5d56347ddf Typo 2016-08-07 23:26:30 +02:00
Eduardo Gulias Davis 80ad87acdd Update composer instructions 2016-08-07 23:25:34 +02:00
Eduardo Gulias Davis 30562b69fc Merge branch 'taz77-correct-readme-php-example-code-php-dependencies' 2016-08-07 23:18:59 +02:00
Eduardo Gulias Davis cbb8b9e152 PHPStorm help and composer suggestion 2016-08-07 23:16:06 +02:00
Eduardo Gulias Davis cf670406e5 Merge branch 'correct-readme-php-example-code-php-dependencies' of https://github.com/taz77/EmailValidator into taz77-correct-readme-php-example-code-php-dependencies 2016-08-07 23:11:36 +02:00
Issei.M 4d446bf971 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
2016-08-03 22:42:12 +02:00
Issei.M 4f0f9023f0 MultipleValidationWithAnd::getError() now returns NULL if no errors (#124)
* MultipleValidationWithAnd::getError() now returns NULL if no errors

* improve adding error logic

* reword something, add tips

* fix CS
remove wrong tips
2016-07-29 22:43:15 +02:00
Brady 9160e26b13 List and links
Turned requirements into an unordered list. Removed the PHPstorm logo as it doesn't exist and could not find one to replace it.
2016-07-19 06:49:04 +02:00
Brady eb036b7d1c Correct PHP example. Add a requirements section.
Corrected PHP example for missing semi-colons. Added a new requirements section that explains the need for composer and the need of the PHP Intl library to use the spoof validation.
2016-07-18 11:55:21 +02:00
27 changed files with 427 additions and 164 deletions
+1
View File
@@ -1,2 +1,3 @@
report/
vendor/
.idea
+1 -2
View File
@@ -27,8 +27,7 @@ install:
script:
- mkdir -p build/logs
- phpunit --coverage-clover build/logs/clover.xml
- vendor/bin/phpunit --coverage-clover build/logs/clover.xml
after_script:
- php vendor/bin/coveralls
-2
View File
@@ -67,8 +67,6 @@ class EmailLexer extends AbstractLexer
"\n" => self::S_LF,
"\r\n" => self::CRLF,
'IPv6' => self::S_IPV6TAG,
'<' => self::S_LOWERTHAN,
'>' => self::S_GREATERTHAN,
'{' => self::S_OPENQBRACKET,
'}' => self::S_CLOSEQBRACKET,
'' => self::S_EMPTY,
+3 -3
View File
@@ -11,7 +11,7 @@ class EmailValidator
* @var EmailLexer
*/
private $lexer;
/**
* @var array
*/
@@ -21,7 +21,7 @@ class EmailValidator
* @var InvalidEmail
*/
protected $error;
public function __construct()
{
$this->lexer = new EmailLexer();
@@ -37,7 +37,7 @@ class EmailValidator
$isValid = $emailValidation->isValid($email, $this->lexer);
$this->warnings = $emailValidation->getWarnings();
$this->error = $emailValidation->getError();
return $isValid;
}
+1 -1
View File
@@ -6,7 +6,7 @@ abstract class InvalidEmail extends \InvalidArgumentException
{
const REASON = "Invalid email";
const CODE = 0;
public function __construct()
{
parent::__construct(static::REASON, static::CODE);
+1 -1
View File
@@ -170,7 +170,7 @@ class DomainPart extends Parser
return $domain;
}
private function checkNotAllowedChars($token)
{
$notAllowed = [EmailLexer::S_BACKSLASH => true, EmailLexer::S_SLASH=> true];
@@ -44,9 +44,11 @@ class DNSCheckValidation implements EmailValidation
protected function checkDNS($host)
{
$host = rtrim($host, '.') . '.';
$Aresult = true;
$MXresult = checkdnsrr($host, 'MX');
if (!$MXresult) {
$this->warnings[NoDNSMXRecord::CODE] = new NoDNSMXRecord();
$Aresult = checkdnsrr($host, 'A') || checkdnsrr($host, 'AAAA');
+15 -2
View File
@@ -4,18 +4,31 @@ namespace Egulias\EmailValidator\Validation;
use Egulias\EmailValidator\EmailLexer;
use Egulias\EmailValidator\Exception\InvalidEmail;
use Egulias\EmailValidator\Warning\Warning;
interface EmailValidation
{
/**
* Returns true if the given email is valid.
*
* @param string $email The email you want to validate.
* @param EmailLexer $emailLexer The email lexer.
*
* @return bool
*/
public function isValid($email, EmailLexer $emailLexer);
/**
* @return InvalidEmail
* Returns the validation error.
*
* @return InvalidEmail|null
*/
public function getError();
/**
* @return array of Warning
* Returns the validation warnings.
*
* @return Warning[]
*/
public function getWarnings();
}
@@ -0,0 +1,11 @@
<?php
namespace Egulias\EmailValidator\Validation\Error;
use Egulias\EmailValidator\Exception\InvalidEmail;
class RFCWarnings extends InvalidEmail
{
const CODE = 997;
const REASON = 'Warnings were found.';
}
+2 -2
View File
@@ -12,13 +12,13 @@ class MultipleErrors extends InvalidEmail
* @var array
*/
private $errors = [];
public function __construct(array $errors)
{
$this->errors = $errors;
parent::__construct();
}
public function getErrors()
{
return $this->errors;
@@ -3,7 +3,6 @@
namespace Egulias\EmailValidator\Validation;
use Egulias\EmailValidator\EmailLexer;
use Egulias\EmailValidator\Exception\InvalidEmail;
use Egulias\EmailValidator\Validation\Exception\EmptyValidationList;
class MultipleValidationWithAnd implements EmailValidation
@@ -49,7 +48,7 @@ class MultipleValidationWithAnd implements EmailValidation
if (count($validations) == 0) {
throw new EmptyValidationList();
}
$this->validations = $validations;
$this->mode = $mode;
}
@@ -65,17 +64,29 @@ class MultipleValidationWithAnd implements EmailValidation
$emailLexer->reset();
$result = $result && $validation->isValid($email, $emailLexer);
$this->warnings = array_merge($this->warnings, $validation->getWarnings());
$errors[] = $validation->getError();
$errors = $this->addNewError($validation->getError(), $errors);
if ($this->shouldStop($result)) {
break;
}
}
$this->error = new MultipleErrors($errors);
if (!empty($errors)) {
$this->error = new MultipleErrors($errors);
}
return $result;
}
private function addNewError($possibleError, array $errors)
{
if (null !== $possibleError) {
$errors[] = $possibleError;
}
return $errors;
}
private function shouldStop($result)
{
return !$result && $this->mode === self::STOP_ON_ERROR;
@@ -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();
}
}
+2 -2
View File
@@ -22,7 +22,7 @@ class RFCValidation implements EmailValidation
* @var InvalidEmail
*/
private $error;
public function isValid($email, EmailLexer $emailLexer)
{
$this->parser = new EmailParser($emailLexer);
@@ -32,7 +32,7 @@ class RFCValidation implements EmailValidation
$this->error = $invalid;
return false;
}
$this->warnings = $this->parser->getWarnings();
return true;
}
@@ -13,16 +13,23 @@ class SpoofCheckValidation implements EmailValidation
* @var InvalidEmail
*/
private $error;
public function __construct()
{
if (!class_exists(Spoofchecker::class)) {
throw new \LogicException(sprintf('The %s class requires the Intl extension.', __CLASS__));
}
}
public function isValid($email, EmailLexer $emailLexer)
{
$checker = new Spoofchecker();
$checker->setChecks(Spoofchecker::SINGLE_SCRIPT);
if ($checker->isSuspicious($email)) {
$this->error = new SpoofEmail();
}
return $this->error === null;
}
+1 -1
View File
@@ -22,7 +22,7 @@ abstract class Warning
{
return $this->rfcNumber;
}
public function __toString()
{
return $this->message() . " rfc: " . $this->rfcNumber . "interal code: " . static::CODE;
+19 -14
View File
@@ -1,18 +1,22 @@
#EmailValidator
# EmailValidator
[![Build Status](https://travis-ci.org/egulias/EmailValidator.png?branch=master)](https://travis-ci.org/egulias/EmailValidator) [![Coverage Status](https://coveralls.io/repos/egulias/EmailValidator/badge.png?branch=master)](https://coveralls.io/r/egulias/EmailValidator?branch=master) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/egulias/EmailValidator/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/egulias/EmailValidator/?branch=master) [![SensioLabsInsight](https://insight.sensiolabs.com/projects/22ba6692-9c02-42e5-a65d-1c5696bfffc6/small.png)](https://insight.sensiolabs.com/projects/22ba6692-9c02-42e5-a65d-1c5696bfffc6)
=============================
With the help of
With the help of [PHPStorm](https://www.jetbrains.com/phpstorm/)
![Powered by PhpStorm](https://www.jetbrains.com/phpstorm/documentation/docs/logo_phpstorm.png)
##Installation##
## Requirements ##
* [Composer](https://getcomposer.org) is required for installation
* [Spoofchecking](https://github.com/egulias/EmailValidator/blob/master/EmailValidator/Validation/SpoofCheckValidation.php) validation requires that your PHP system have the [PHP Internationalization Libraries](http://php.net/manual/en/book.intl.php) (also known as PHP Intl)
## Installation ##
Run the command below to install via Composer
```shell
composer require egulias/email-validator "~2.0"
composer require egulias/email-validator "~2.1"
```
##Getting Started##
## Getting Started ##
`EmailValidator`requires you to decide which (or combination of them) validation/s strategy/ies you'd like to follow for each [validation](#available-validations).
A basic example with the RFC validation
@@ -20,16 +24,17 @@ A basic example with the RFC validation
<?php
use Egulias\EmailValidator\EmailValidator;
use Egulias\EmailValidator\Validation\RFCValidation;
$validator = new EmailValidator();
$validator->isValid("example@example.com", new RFCValidation()) //true
$validator->isValid("example@example.com", new RFCValidation()); //true
```
###Available validations###
### Available validations ###
1. [RFCValidation](https://github.com/egulias/EmailValidator/blob/master/EmailValidator/Validation/RFCValidation.php)
2. [NoWarningsRFCValidation](https://github.com/egulias/EmailValidator/blob/master/EmailValidator/Validation/NoRFCWarningsValidation.php)
2. [NoRFCWarningsValidation](https://github.com/egulias/EmailValidator/blob/master/EmailValidator/Validation/NoRFCWarningsValidation.php)
3. [DNSCheckValidation](https://github.com/egulias/EmailValidator/blob/master/EmailValidator/Validation/DNSCheckValidation.php)
4. [SpoofCheckValidation](https://github.com/egulias/EmailValidator/blob/master/EmailValidator/Validation/SpoofCheckValidation.php)
5. [MultipleValidationWithAnd](https://github.com/egulias/EmailValidator/blob/master/EmailValidator/Validation/MultipleValidationWithAnd.php)
@@ -51,16 +56,16 @@ $validator = new EmailValidator();
$multipleValidations = new MultipleValidationWithAnd([
new RFCValidation(),
new DNSCheckValidation()
])
$validator->isValid("example@example.com", $multipleValidations) //true
]);
$validator->isValid("example@example.com", $multipleValidations); //true
```
###How to extend###
### How to extend ###
It's easy! You just need to extend [EmailValidation](https://github.com/egulias/EmailValidator/blob/master/EmailValidator/Validation/EmailValidation.php) and you can use your own validation.
##Other Contributors##
## Other Contributors ##
(You can find current contributors [here](https://github.com/egulias/EmailValidator/graphs/contributors))
As this is a port from another library and work, here are other people related to the previous one:
@@ -69,6 +74,6 @@ As this is a port from another library and work, here are other people related t
* Josepf Bielawski [@stloyd](http://github.com/stloyd): For its first re-work of Dominic's lib
* Dominic Sayers [@dominicsayers](http://github.com/dominicsayers): The original isemail function
##License##
## License ##
Released under the MIT License attached with this code.
+2 -1
View File
@@ -3,8 +3,9 @@
namespace Egulias\Tests\EmailValidator;
use Egulias\EmailValidator\EmailLexer;
use PHPUnit\Framework\TestCase;
class EmailLexerTests extends \PHPUnit_Framework_TestCase
class EmailLexerTests extends TestCase
{
public function testLexerExtendsLib()
+5 -4
View File
@@ -4,24 +4,25 @@ namespace Egulias\Tests\EmailValidator;
use Egulias\EmailValidator\EmailValidator;
use Egulias\EmailValidator\Validation\MultipleValidationWithAnd;
use PHPUnit\Framework\TestCase;
class EmailValidatorTest extends \PHPUnit_Framework_TestCase
class EmailValidatorTest extends TestCase
{
public function testValidationIsUsed()
{
$validator = new EmailValidator();
$validation = $this->getMock("Egulias\\EmailValidator\\Validation\\EmailValidation");
$validation = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
$validation->expects($this->once())->method("isValid")->willReturn(true);
$validation->expects($this->once())->method("getWarnings")->willReturn([]);
$validation->expects($this->once())->method("getError")->willReturn(null);
$this->assertTrue($validator->isValid("example@example.com", $validation));
}
public function testMultipleValidation()
{
$validator = new EmailValidator();
$validation = $this->getMock("Egulias\\EmailValidator\\Validation\\EmailValidation");
$validation = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
$validation->expects($this->once())->method("isValid")->willReturn(true);
$validation->expects($this->once())->method("getWarnings")->willReturn([]);
$validation->expects($this->once())->method("getError")->willReturn(null);
@@ -6,8 +6,9 @@ use Egulias\EmailValidator\EmailLexer;
use Egulias\EmailValidator\Exception\NoDNSRecord;
use Egulias\EmailValidator\Validation\DNSCheckValidation;
use Egulias\EmailValidator\Warning\NoDNSMXRecord;
use PHPUnit\Framework\TestCase;
class DNSCheckValidationTest extends \PHPUnit_Framework_TestCase
class DNSCheckValidationTest extends TestCase
{
public function validEmailsProvider()
{
@@ -34,13 +35,13 @@ class DNSCheckValidationTest extends \PHPUnit_Framework_TestCase
$validation = new DNSCheckValidation();
$this->assertTrue($validation->isValid($validEmail, new EmailLexer()));
}
public function testInvalidDNS()
{
$validation = new DNSCheckValidation();
$this->assertFalse($validation->isValid("example@invalid.example.com", new EmailLexer()));
}
public function testDNSWarnings()
{
$validation = new DNSCheckValidation();
@@ -48,7 +49,7 @@ class DNSCheckValidationTest extends \PHPUnit_Framework_TestCase
$validation->isValid("example@invalid.example.com", new EmailLexer());
$this->assertEquals($expectedWarnings, $validation->getWarnings());
}
public function testNoDNSError()
{
$validation = new DNSCheckValidation();
@@ -7,8 +7,9 @@ use Egulias\EmailValidator\Validation\DNSCheckValidation;
use Egulias\EmailValidator\Validation\MultipleValidationWithAnd;
use Egulias\EmailValidator\Validation\NoRFCWarningsValidation;
use Egulias\EmailValidator\Validation\RFCValidation;
use PHPUnit\Framework\TestCase;
class IsEmailFunctionTests extends \PHPUnit_Framework_TestCase
class IsEmailFunctionTests extends TestCase
{
/**
* @dataProvider isEmailTestSuite
@@ -28,8 +29,8 @@ class IsEmailFunctionTests extends \PHPUnit_Framework_TestCase
public function isEmailTestSuite()
{
$testSuite = dirname(__FILE__) . '/../../resources/is_email_tests.xml';
$document = new \DOMDocument();
$document->load($testSuite);
$document = new \DOMDocument();
$document->load($testSuite);
$elements = $document->getElementsByTagName('test');
$tests = [];
@@ -40,5 +41,4 @@ class IsEmailFunctionTests extends \PHPUnit_Framework_TestCase
return $tests;
}
}
@@ -8,16 +8,17 @@ use Egulias\EmailValidator\Validation\MultipleErrors;
use Egulias\EmailValidator\Validation\MultipleValidationWithAnd;
use Egulias\EmailValidator\Warning\AddressLiteral;
use Egulias\EmailValidator\Warning\DomainLiteral;
use PHPUnit\Framework\TestCase;
class MultipleValidationWitAndTest extends \PHPUnit_Framework_TestCase
class MultipleValidationWitAndTest extends TestCase
{
public function testUsesAndLogicalOperation()
{
$lexer = $this->getMock("Egulias\\EmailValidator\\EmailLexer");
$validationTrue = $this->getMock("Egulias\\EmailValidator\\Validation\\EmailValidation");
$lexer = $this->getMockBuilder("Egulias\\EmailValidator\\EmailLexer")->getMock();
$validationTrue = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
$validationTrue->expects($this->any())->method("isValid")->willReturn(true);
$validationTrue->expects($this->any())->method("getWarnings")->willReturn([]);
$validationFalse = $this->getMock("Egulias\\EmailValidator\\Validation\\EmailValidation");
$validationFalse = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
$validationFalse->expects($this->any())->method("isValid")->willReturn(false);
$validationFalse->expects($this->any())->method("getWarnings")->willReturn([]);
$multipleValidation = new MultipleValidationWithAnd([$validationTrue, $validationFalse]);
@@ -32,6 +33,19 @@ class MultipleValidationWitAndTest extends \PHPUnit_Framework_TestCase
new MultipleValidationWithAnd([]);
}
public function testValidationIsValid()
{
$lexer = $this->getMockBuilder("Egulias\\EmailValidator\\EmailLexer")->getMock();
$validation = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
$validation->expects($this->any())->method("isValid")->willReturn(true);
$validation->expects($this->once())->method("getWarnings")->willReturn([]);
$multipleValidation = new MultipleValidationWithAnd([$validation]);
$this->assertTrue($multipleValidation->isValid("example@example.com", $lexer));
$this->assertNull($multipleValidation->getError());
}
public function testAccumulatesWarnings()
{
$warnings1 = [
@@ -41,16 +55,17 @@ class MultipleValidationWitAndTest extends \PHPUnit_Framework_TestCase
DomainLiteral::CODE => new DomainLiteral()
];
$expectedResult = array_merge($warnings1, $warnings2);
$lexer = $this->getMock("Egulias\\EmailValidator\\EmailLexer");
$validation1 = $this->getMock("Egulias\\EmailValidator\\Validation\\EmailValidation");
$lexer = $this->getMockBuilder("Egulias\\EmailValidator\\EmailLexer")->getMock();
$validation1 = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
$validation1->expects($this->any())->method("isValid")->willReturn(true);
$validation1->expects($this->once())->method("getWarnings")->willReturn($warnings1);
$validation2 = $this->getMock("Egulias\\EmailValidator\\Validation\\EmailValidation");
$validation2 = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
$validation2->expects($this->any())->method("isValid")->willReturn(false);
$validation2->expects($this->once())->method("getWarnings")->willReturn($warnings2);
$multipleValidation = new MultipleValidationWithAnd([$validation1, $validation2]);
$multipleValidation->isValid("example@example.com", $lexer);
$this->assertEquals($expectedResult, $multipleValidation->getWarnings());
@@ -60,17 +75,17 @@ class MultipleValidationWitAndTest extends \PHPUnit_Framework_TestCase
{
$error1 = new CommaInDomain();
$error2 = new NoDomainPart();
$expectedResult = new MultipleErrors([$error1, $error2]);
$lexer = $this->getMock("Egulias\\EmailValidator\\EmailLexer");
$validation1 = $this->getMock("Egulias\\EmailValidator\\Validation\\EmailValidation");
$lexer = $this->getMockBuilder("Egulias\\EmailValidator\\EmailLexer")->getMock();
$validation1 = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
$validation1->expects($this->any())->method("isValid")->willReturn(true);
$validation1->expects($this->once())->method("getWarnings")->willReturn([]);
$validation1->expects($this->once())->method("getError")->willReturn($error1);
$validation2 = $this->getMock("Egulias\\EmailValidator\\Validation\\EmailValidation");
$validation2 = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
$validation2->expects($this->any())->method("isValid")->willReturn(false);
$validation2->expects($this->once())->method("getWarnings")->willReturn([]);
$validation2->expects($this->once())->method("getError")->willReturn($error2);
@@ -86,14 +101,14 @@ class MultipleValidationWitAndTest extends \PHPUnit_Framework_TestCase
$expectedResult = new MultipleErrors([$error]);
$lexer = $this->getMock("Egulias\\EmailValidator\\EmailLexer");
$lexer = $this->getMockBuilder("Egulias\\EmailValidator\\EmailLexer")->getMock();
$validation1 = $this->getMock("Egulias\\EmailValidator\\Validation\\EmailValidation");
$validation1 = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
$validation1->expects($this->any())->method("isValid")->willReturn(false);
$validation1->expects($this->once())->method("getWarnings")->willReturn([]);
$validation1->expects($this->once())->method("getError")->willReturn($error);
$validation2 = $this->getMock("Egulias\\EmailValidator\\Validation\\EmailValidation");
$validation2 = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
$validation2->expects($this->never())->method("isValid");
$validation2->expects($this->never())->method("getWarnings");
$validation2->expects($this->never())->method("getError");
@@ -0,0 +1,36 @@
<?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;
use PHPUnit\Framework\TestCase;
class NoRFCWarningsValidationTest extends 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('example@example.com', new EmailLexer()));
$this->assertNull($validation->getError());
}
}
@@ -1,23 +0,0 @@
<?php
namespace Egulias\Tests\EmailValidator\Validation;
use Egulias\EmailValidator\EmailLexer;
use Egulias\EmailValidator\Validation\NoRFCWarningsValidation;
class NoWarningsRFCValidationTest extends \PHPUnit_Framework_TestCase
{
public function testEmailWithWarningsIsInvalid()
{
$validation = new NoRFCWarningsValidation();
$this->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()));
}
}
@@ -35,8 +35,9 @@ use Egulias\EmailValidator\Warning\LabelTooLong;
use Egulias\EmailValidator\Warning\LocalTooLong;
use Egulias\EmailValidator\Warning\ObsoleteDTEXT;
use Egulias\EmailValidator\Warning\QuotedString;
use PHPUnit\Framework\TestCase;
class RFCValidationTest extends \PHPUnit_Framework_TestCase
class RFCValidationTest extends TestCase
{
/**
* @var RFCValidation
@@ -47,7 +48,7 @@ class RFCValidationTest extends \PHPUnit_Framework_TestCase
* @var EmailLexer
*/
protected $lexer;
protected function setUp()
{
$this->validator = new RFCValidation();
@@ -106,7 +107,7 @@ class RFCValidationTest extends \PHPUnit_Framework_TestCase
$email = "\x80\x81\x82@\x83\x84\x85.\x86\x87\x88";
$this->assertFalse($this->validator->isValid($email, $this->lexer));
}
/**
* @dataProvider getInvalidEmails
*/
@@ -228,7 +229,7 @@ class RFCValidationTest extends \PHPUnit_Framework_TestCase
$this->assertTrue(isset($expectedWarnings[$warning->code()]));
}
}
public function getInvalidEmailsWithWarnings()
{
return [
@@ -4,8 +4,9 @@ namespace Egulias\Tests\EmailValidator\Validation;
use Egulias\EmailValidator\EmailLexer;
use Egulias\EmailValidator\Validation\SpoofCheckValidation;
use PHPUnit\Framework\TestCase;
class SpoofCheckValidationTest extends \PHPUnit_Framework_TestCase
class SpoofCheckValidationTest extends TestCase
{
/**
* @dataProvider validUTF8EmailsProvider
@@ -14,17 +15,17 @@ class SpoofCheckValidationTest extends \PHPUnit_Framework_TestCase
{
$this->markTestSkipped("Skipped for Travis CI since it is failing on this test for unknown reasons.");
$validation = new SpoofCheckValidation();
$this->assertTrue($validation->isValid($email, new EmailLexer()));
}
public function testEmailWithSpoofsIsInvalid()
{
$validation = new SpoofCheckValidation();
$this->assertFalse($validation->isValid("Кириллица"."latin漢字"."ひらがな"."カタカナ", new EmailLexer()));
}
public function validUTF8EmailsProvider()
{
return [
+5 -2
View File
@@ -24,10 +24,13 @@
"doctrine/lexer": "^1.0.1"
},
"require-dev" : {
"satooshi/php-coveralls": "dev-master",
"phpunit/phpunit": "^4.8.0",
"satooshi/php-coveralls": "^1.0.1",
"phpunit/phpunit": "^4.8.35",
"dominicsayers/isemail": "dev-master"
},
"suggest": {
"ext-intl": "PHP Internationalization Libraries are required to use the SpoofChecking validation"
},
"autoload": {
"psr-4": {
"Egulias\\EmailValidator\\": "EmailValidator"
Generated
+213 -61
View File
@@ -4,8 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "cd8cdb976fb5cd5012d94c224aa4fd4b",
"content-hash": "b0395bec21f73086fad52837dc689634",
"content-hash": "d260b2d1d79771429aea640320702483",
"packages": [
{
"name": "doctrine/lexer",
@@ -59,7 +58,7 @@
"lexer",
"parser"
],
"time": "2014-09-09 13:34:57"
"time": "2014-09-09T13:34:57+00:00"
}
],
"packages-dev": [
@@ -115,7 +114,7 @@
"constructor",
"instantiate"
],
"time": "2015-06-14 21:17:01"
"time": "2015-06-14T21:17:01+00:00"
},
{
"name": "dominicsayers/isemail",
@@ -150,7 +149,103 @@
"source": "https://github.com/dominicsayers/isemail",
"issues": "https://github.com/dominicsayers/isemail/issues"
},
"time": "2014-11-26 12:46:56"
"time": "2014-11-26T12:46:56+00:00"
},
{
"name": "guzzle/guzzle",
"version": "v3.9.3",
"source": {
"type": "git",
"url": "https://github.com/guzzle/guzzle3.git",
"reference": "0645b70d953bc1c067bbc8d5bc53194706b628d9"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/guzzle3/zipball/0645b70d953bc1c067bbc8d5bc53194706b628d9",
"reference": "0645b70d953bc1c067bbc8d5bc53194706b628d9",
"shasum": ""
},
"require": {
"ext-curl": "*",
"php": ">=5.3.3",
"symfony/event-dispatcher": "~2.1"
},
"replace": {
"guzzle/batch": "self.version",
"guzzle/cache": "self.version",
"guzzle/common": "self.version",
"guzzle/http": "self.version",
"guzzle/inflection": "self.version",
"guzzle/iterator": "self.version",
"guzzle/log": "self.version",
"guzzle/parser": "self.version",
"guzzle/plugin": "self.version",
"guzzle/plugin-async": "self.version",
"guzzle/plugin-backoff": "self.version",
"guzzle/plugin-cache": "self.version",
"guzzle/plugin-cookie": "self.version",
"guzzle/plugin-curlauth": "self.version",
"guzzle/plugin-error-response": "self.version",
"guzzle/plugin-history": "self.version",
"guzzle/plugin-log": "self.version",
"guzzle/plugin-md5": "self.version",
"guzzle/plugin-mock": "self.version",
"guzzle/plugin-oauth": "self.version",
"guzzle/service": "self.version",
"guzzle/stream": "self.version"
},
"require-dev": {
"doctrine/cache": "~1.3",
"monolog/monolog": "~1.0",
"phpunit/phpunit": "3.7.*",
"psr/log": "~1.0",
"symfony/class-loader": "~2.1",
"zendframework/zend-cache": "2.*,<2.3",
"zendframework/zend-log": "2.*,<2.3"
},
"suggest": {
"guzzlehttp/guzzle": "Guzzle 5 has moved to a new package name. The package you have installed, Guzzle 3, is deprecated."
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.9-dev"
}
},
"autoload": {
"psr-0": {
"Guzzle": "src/",
"Guzzle\\Tests": "tests/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
},
{
"name": "Guzzle Community",
"homepage": "https://github.com/guzzle/guzzle/contributors"
}
],
"description": "PHP HTTP client. This library is deprecated in favor of https://packagist.org/packages/guzzlehttp/guzzle",
"homepage": "http://guzzlephp.org/",
"keywords": [
"client",
"curl",
"framework",
"http",
"http client",
"rest",
"web service"
],
"abandoned": "guzzlehttp/guzzle",
"time": "2015-03-18T18:23:50+00:00"
},
{
"name": "guzzlehttp/guzzle",
@@ -212,7 +307,7 @@
"rest",
"web service"
],
"time": "2016-03-21 20:02:09"
"time": "2016-03-21T20:02:09+00:00"
},
{
"name": "guzzlehttp/promises",
@@ -263,7 +358,7 @@
"keywords": [
"promise"
],
"time": "2016-03-08 01:15:46"
"time": "2016-03-08T01:15:46+00:00"
},
{
"name": "guzzlehttp/psr7",
@@ -321,7 +416,7 @@
"stream",
"uri"
],
"time": "2016-04-13 19:56:01"
"time": "2016-04-13T19:56:01+00:00"
},
{
"name": "phpdocumentor/reflection-docblock",
@@ -370,7 +465,7 @@
"email": "mike.vanriel@naenius.com"
}
],
"time": "2015-02-03 12:10:50"
"time": "2015-02-03T12:10:50+00:00"
},
{
"name": "phpspec/prophecy",
@@ -432,7 +527,7 @@
"spy",
"stub"
],
"time": "2016-02-15 07:46:21"
"time": "2016-02-15T07:46:21+00:00"
},
{
"name": "phpunit/php-code-coverage",
@@ -494,7 +589,7 @@
"testing",
"xunit"
],
"time": "2015-10-06 15:47:00"
"time": "2015-10-06T15:47:00+00:00"
},
{
"name": "phpunit/php-file-iterator",
@@ -541,7 +636,7 @@
"filesystem",
"iterator"
],
"time": "2015-06-21 13:08:43"
"time": "2015-06-21T13:08:43+00:00"
},
{
"name": "phpunit/php-text-template",
@@ -582,7 +677,7 @@
"keywords": [
"template"
],
"time": "2015-06-21 13:50:34"
"time": "2015-06-21T13:50:34+00:00"
},
{
"name": "phpunit/php-timer",
@@ -626,7 +721,7 @@
"keywords": [
"timer"
],
"time": "2016-05-12 18:03:57"
"time": "2016-05-12T18:03:57+00:00"
},
{
"name": "phpunit/php-token-stream",
@@ -675,20 +770,20 @@
"keywords": [
"tokenizer"
],
"time": "2015-09-15 10:49:45"
"time": "2015-09-15T10:49:45+00:00"
},
{
"name": "phpunit/phpunit",
"version": "4.8.25",
"version": "4.8.36",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "6d1588a6542a52ed89636e5a9876bc7502bbb853"
"reference": "46023de9a91eec7dfb06cc56cb4e260017298517"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/6d1588a6542a52ed89636e5a9876bc7502bbb853",
"reference": "6d1588a6542a52ed89636e5a9876bc7502bbb853",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/46023de9a91eec7dfb06cc56cb4e260017298517",
"reference": "46023de9a91eec7dfb06cc56cb4e260017298517",
"shasum": ""
},
"require": {
@@ -704,7 +799,7 @@
"phpunit/php-text-template": "~1.2",
"phpunit/php-timer": "^1.0.6",
"phpunit/phpunit-mock-objects": "~2.3",
"sebastian/comparator": "~1.1",
"sebastian/comparator": "~1.2.2",
"sebastian/diff": "~1.2",
"sebastian/environment": "~1.3",
"sebastian/exporter": "~1.2",
@@ -747,7 +842,7 @@
"testing",
"xunit"
],
"time": "2016-05-10 18:47:12"
"time": "2017-06-21T08:07:12+00:00"
},
{
"name": "phpunit/phpunit-mock-objects",
@@ -803,7 +898,7 @@
"mock",
"xunit"
],
"time": "2015-10-02 06:51:40"
"time": "2015-10-02T06:51:40+00:00"
},
{
"name": "psr/http-message",
@@ -852,7 +947,7 @@
"request",
"response"
],
"time": "2015-05-04 20:22:00"
"time": "2015-05-04T20:22:00+00:00"
},
{
"name": "psr/log",
@@ -890,32 +985,35 @@
"psr",
"psr-3"
],
"time": "2012-12-21 11:40:51"
"time": "2012-12-21T11:40:51+00:00"
},
{
"name": "satooshi/php-coveralls",
"version": "dev-master",
"version": "v1.0.2",
"source": {
"type": "git",
"url": "https://github.com/satooshi/php-coveralls.git",
"reference": "50c60bb64054974f8ed7540ae6e75fd7981a5fd3"
"url": "https://github.com/php-coveralls/php-coveralls.git",
"reference": "9c07b63acbc9709344948b6fd4f63a32b2ef4127"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/satooshi/php-coveralls/zipball/50c60bb64054974f8ed7540ae6e75fd7981a5fd3",
"reference": "50c60bb64054974f8ed7540ae6e75fd7981a5fd3",
"url": "https://api.github.com/repos/php-coveralls/php-coveralls/zipball/9c07b63acbc9709344948b6fd4f63a32b2ef4127",
"reference": "9c07b63acbc9709344948b6fd4f63a32b2ef4127",
"shasum": ""
},
"require": {
"ext-json": "*",
"ext-simplexml": "*",
"guzzlehttp/guzzle": "^6.0",
"php": ">=5.5",
"guzzle/guzzle": "^2.8 || ^3.0",
"php": "^5.3.3 || ^7.0",
"psr/log": "^1.0",
"symfony/config": "^2.1|^3.0",
"symfony/console": "^2.1|^3.0",
"symfony/stopwatch": "^2.0|^3.0",
"symfony/yaml": "^2.0|^3.0"
"symfony/config": "^2.1 || ^3.0 || ^4.0",
"symfony/console": "^2.1 || ^3.0 || ^4.0",
"symfony/stopwatch": "^2.0 || ^3.0 || ^4.0",
"symfony/yaml": "^2.0 || ^3.0 || ^4.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8.35 || ^5.4.3 || ^6.0"
},
"suggest": {
"symfony/http-kernel": "Allows Symfony integration"
@@ -924,11 +1022,6 @@
"bin/coveralls"
],
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.0-dev"
}
},
"autoload": {
"psr-4": {
"Satooshi\\": "src/Satooshi/"
@@ -946,33 +1039,33 @@
}
],
"description": "PHP client library for Coveralls API",
"homepage": "https://github.com/satooshi/php-coveralls",
"homepage": "https://github.com/php-coveralls/php-coveralls",
"keywords": [
"ci",
"coverage",
"github",
"test"
],
"time": "2016-01-20 17:44:41"
"time": "2017-10-14T23:15:34+00:00"
},
{
"name": "sebastian/comparator",
"version": "1.2.0",
"version": "1.2.4",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/comparator.git",
"reference": "937efb279bd37a375bcadf584dec0726f84dbf22"
"reference": "2b7424b55f5047b47ac6e5ccb20b2aea4011d9be"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/937efb279bd37a375bcadf584dec0726f84dbf22",
"reference": "937efb279bd37a375bcadf584dec0726f84dbf22",
"url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/2b7424b55f5047b47ac6e5ccb20b2aea4011d9be",
"reference": "2b7424b55f5047b47ac6e5ccb20b2aea4011d9be",
"shasum": ""
},
"require": {
"php": ">=5.3.3",
"sebastian/diff": "~1.2",
"sebastian/exporter": "~1.2"
"sebastian/exporter": "~1.2 || ~2.0"
},
"require-dev": {
"phpunit/phpunit": "~4.4"
@@ -1017,7 +1110,7 @@
"compare",
"equality"
],
"time": "2015-07-26 15:48:44"
"time": "2017-01-29T09:50:25+00:00"
},
{
"name": "sebastian/diff",
@@ -1069,7 +1162,7 @@
"keywords": [
"diff"
],
"time": "2015-12-08 07:14:41"
"time": "2015-12-08T07:14:41+00:00"
},
{
"name": "sebastian/environment",
@@ -1119,7 +1212,7 @@
"environment",
"hhvm"
],
"time": "2016-05-04 07:59:13"
"time": "2016-05-04T07:59:13+00:00"
},
{
"name": "sebastian/exporter",
@@ -1185,7 +1278,7 @@
"export",
"exporter"
],
"time": "2015-06-21 07:55:53"
"time": "2015-06-21T07:55:53+00:00"
},
{
"name": "sebastian/global-state",
@@ -1236,7 +1329,7 @@
"keywords": [
"global state"
],
"time": "2015-10-12 03:26:01"
"time": "2015-10-12T03:26:01+00:00"
},
{
"name": "sebastian/recursion-context",
@@ -1289,7 +1382,7 @@
],
"description": "Provides functionality to recursively process PHP variables",
"homepage": "http://www.github.com/sebastianbergmann/recursion-context",
"time": "2015-11-11 19:50:13"
"time": "2015-11-11T19:50:13+00:00"
},
{
"name": "sebastian/version",
@@ -1324,7 +1417,7 @@
],
"description": "Library that helps with managing the version number of Git-hosted PHP projects",
"homepage": "https://github.com/sebastianbergmann/version",
"time": "2015-06-21 13:59:46"
"time": "2015-06-21T13:59:46+00:00"
},
{
"name": "symfony/config",
@@ -1377,7 +1470,7 @@
],
"description": "Symfony Config Component",
"homepage": "https://symfony.com",
"time": "2016-04-20 18:53:54"
"time": "2016-04-20T18:53:54+00:00"
},
{
"name": "symfony/console",
@@ -1437,7 +1530,67 @@
],
"description": "Symfony Console Component",
"homepage": "https://symfony.com",
"time": "2016-04-28 09:48:42"
"time": "2016-04-28T09:48:42+00:00"
},
{
"name": "symfony/event-dispatcher",
"version": "v2.8.30",
"source": {
"type": "git",
"url": "https://github.com/symfony/event-dispatcher.git",
"reference": "b59aacf238fadda50d612c9de73b74751872a903"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/b59aacf238fadda50d612c9de73b74751872a903",
"reference": "b59aacf238fadda50d612c9de73b74751872a903",
"shasum": ""
},
"require": {
"php": ">=5.3.9"
},
"require-dev": {
"psr/log": "~1.0",
"symfony/config": "^2.0.5|~3.0.0",
"symfony/dependency-injection": "~2.6|~3.0.0",
"symfony/expression-language": "~2.6|~3.0.0",
"symfony/stopwatch": "~2.3|~3.0.0"
},
"suggest": {
"symfony/dependency-injection": "",
"symfony/http-kernel": ""
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.8-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Component\\EventDispatcher\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony EventDispatcher Component",
"homepage": "https://symfony.com",
"time": "2017-11-05T15:25:56+00:00"
},
{
"name": "symfony/filesystem",
@@ -1486,7 +1639,7 @@
],
"description": "Symfony Filesystem Component",
"homepage": "https://symfony.com",
"time": "2016-04-12 18:09:53"
"time": "2016-04-12T18:09:53+00:00"
},
{
"name": "symfony/polyfill-mbstring",
@@ -1545,7 +1698,7 @@
"portable",
"shim"
],
"time": "2016-01-20 09:13:37"
"time": "2016-01-20T09:13:37+00:00"
},
{
"name": "symfony/stopwatch",
@@ -1594,7 +1747,7 @@
],
"description": "Symfony Stopwatch Component",
"homepage": "https://symfony.com",
"time": "2016-03-04 07:55:57"
"time": "2016-03-04T07:55:57+00:00"
},
{
"name": "symfony/yaml",
@@ -1643,13 +1796,12 @@
],
"description": "Symfony Yaml Component",
"homepage": "https://symfony.com",
"time": "2016-03-04 07:55:57"
"time": "2016-03-04T07:55:57+00:00"
}
],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": {
"satooshi/php-coveralls": 20,
"dominicsayers/isemail": 20
},
"prefer-stable": false,