mirror of
https://github.com/egulias/EmailValidator.git
synced 2026-09-12 02:56:50 +00:00
Merge branch '3.x' of github.com:egulias/EmailValidator into 3.x
This commit is contained in:
@@ -11,3 +11,4 @@ build:
|
||||
coverage:
|
||||
file: 'clover.xml'
|
||||
format: 'clover'
|
||||
- php-scrutinizer-run
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
# EmailValidator
|
||||
|
||||
[](https://travis-ci.org/egulias/EmailValidator)
|
||||
[](https://app.travis-ci.com/github/egulias/EmailValidator)
|
||||
[](https://scrutinizer-ci.com/g/egulias/EmailValidator/?branch=3.x)
|
||||
[](https://scrutinizer-ci.com/g/egulias/EmailValidator/?branch=3.x)
|
||||
[](https://insight.symfony.com/projects/22ba6692-9c02-42e5-a65d-1c5696bfffc6)
|
||||
|
||||
A library for validating emails against several RFC.
|
||||
|
||||
|
||||
@@ -280,9 +280,9 @@ class DomainPart extends PartParser
|
||||
{
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_DOT || $isEndOfDomain) {
|
||||
if ($this->isLabelTooLong($this->label)) {
|
||||
$this->label = '';
|
||||
return new InvalidEmail(new LabelTooLong(), $this->lexer->token['value']);
|
||||
}
|
||||
$this->label = '';
|
||||
}
|
||||
$this->label .= $this->lexer->token['value'];
|
||||
return new ValidEmail();
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Egulias\EmailValidator\Result;
|
||||
|
||||
use Egulias\EmailValidator\Result\InvalidEmail;
|
||||
use Egulias\EmailValidator\Result\Reason\EmptyReason;
|
||||
use Egulias\EmailValidator\Result\Reason\Reason;
|
||||
|
||||
/**
|
||||
@@ -34,7 +34,9 @@ class MultipleErrors extends InvalidEmail
|
||||
|
||||
public function reason() : Reason
|
||||
{
|
||||
return $this->reasons[0];
|
||||
return 0 !== count($this->reasons)
|
||||
? current($this->reasons)
|
||||
: new EmptyReason();
|
||||
}
|
||||
|
||||
public function description() : string
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Result\Reason;
|
||||
|
||||
class EmptyReason implements Reason
|
||||
{
|
||||
public function code() : int
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function description() : string
|
||||
{
|
||||
return 'Empty reason';
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,11 @@
|
||||
|
||||
namespace Egulias\EmailValidator\Tests\EmailValidator\Reason;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Egulias\EmailValidator\Result\MultipleErrors;
|
||||
use Egulias\EmailValidator\Result\Reason\EmptyReason;
|
||||
use Egulias\EmailValidator\Tests\EmailValidator\Dummy\AnotherDummyReason;
|
||||
use Egulias\EmailValidator\Tests\EmailValidator\Dummy\DummyReason;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class MultipleErrorsTest extends TestCase
|
||||
{
|
||||
@@ -35,4 +36,31 @@ class MultipleErrorsTest extends TestCase
|
||||
$this->assertEquals($expectedReason, $multiError->description());
|
||||
$this->assertEquals($error1, $multiError->reason());
|
||||
}
|
||||
|
||||
public function testRetrieveFirstReasonWithReasonCodeEqualsZero(): void
|
||||
{
|
||||
$error1 = new DummyReason();
|
||||
|
||||
$multiError = new MultipleErrors();
|
||||
$multiError->addReason($error1);
|
||||
|
||||
$this->assertEquals($error1, $multiError->reason());
|
||||
}
|
||||
|
||||
public function testRetrieveFirstReasonWithReasonCodeDistinctToZero(): void
|
||||
{
|
||||
$error1 = new AnotherDummyReason();
|
||||
|
||||
$multiError = new MultipleErrors();
|
||||
$multiError->addReason($error1);
|
||||
|
||||
$this->assertEquals($error1, $multiError->reason());
|
||||
}
|
||||
|
||||
public function testRetrieveFirstReasonWithNoReasonAdded()
|
||||
{
|
||||
$emptyReason = new EmptyReason();
|
||||
$multiError = new MultipleErrors();
|
||||
$this->assertEquals($emptyReason, $multiError->reason());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,6 +76,7 @@ class RFCValidationDomainPartTest extends TestCase
|
||||
['validipv4@[127.0.0.0]'],
|
||||
['validipv4@127.0.0.0'],
|
||||
['withhyphen@domain-exam.com'],
|
||||
['valid_long_domain@71846jnrsoj91yfhc18rkbrf90ue3onl8y46js38kae8inz0t1.5a-xdycuau.na49.le.example.com']
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user