mirror of
https://github.com/egulias/EmailValidator.git
synced 2026-09-05 06:58:21 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ee0db30118 | |||
| c81f18a3ef | |||
| 95979e2ad6 |
@@ -280,9 +280,9 @@ class DomainPart extends PartParser
|
|||||||
{
|
{
|
||||||
if ($this->lexer->token['type'] === EmailLexer::S_DOT || $isEndOfDomain) {
|
if ($this->lexer->token['type'] === EmailLexer::S_DOT || $isEndOfDomain) {
|
||||||
if ($this->isLabelTooLong($this->label)) {
|
if ($this->isLabelTooLong($this->label)) {
|
||||||
$this->label = '';
|
|
||||||
return new InvalidEmail(new LabelTooLong(), $this->lexer->token['value']);
|
return new InvalidEmail(new LabelTooLong(), $this->lexer->token['value']);
|
||||||
}
|
}
|
||||||
|
$this->label = '';
|
||||||
}
|
}
|
||||||
$this->label .= $this->lexer->token['value'];
|
$this->label .= $this->lexer->token['value'];
|
||||||
return new ValidEmail();
|
return new ValidEmail();
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Egulias\EmailValidator\Result;
|
namespace Egulias\EmailValidator\Result;
|
||||||
|
|
||||||
use Egulias\EmailValidator\Result\InvalidEmail;
|
use Egulias\EmailValidator\Result\Reason\EmptyReason;
|
||||||
use Egulias\EmailValidator\Result\Reason\Reason;
|
use Egulias\EmailValidator\Result\Reason\Reason;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -34,7 +34,9 @@ class MultipleErrors extends InvalidEmail
|
|||||||
|
|
||||||
public function reason() : Reason
|
public function reason() : Reason
|
||||||
{
|
{
|
||||||
return $this->reasons[0];
|
return 0 !== count($this->reasons)
|
||||||
|
? current($this->reasons)
|
||||||
|
: new EmptyReason();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function description() : string
|
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';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,7 +21,7 @@ interface EmailValidation
|
|||||||
/**
|
/**
|
||||||
* Returns the validation error.
|
* Returns the validation error.
|
||||||
*
|
*
|
||||||
* @return InvalidEmail
|
* @return InvalidEmail|null
|
||||||
*/
|
*/
|
||||||
public function getError() : ?InvalidEmail;
|
public function getError() : ?InvalidEmail;
|
||||||
|
|
||||||
|
|||||||
@@ -2,10 +2,11 @@
|
|||||||
|
|
||||||
namespace Egulias\EmailValidator\Tests\EmailValidator\Reason;
|
namespace Egulias\EmailValidator\Tests\EmailValidator\Reason;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
use Egulias\EmailValidator\Result\MultipleErrors;
|
use Egulias\EmailValidator\Result\MultipleErrors;
|
||||||
|
use Egulias\EmailValidator\Result\Reason\EmptyReason;
|
||||||
use Egulias\EmailValidator\Tests\EmailValidator\Dummy\AnotherDummyReason;
|
use Egulias\EmailValidator\Tests\EmailValidator\Dummy\AnotherDummyReason;
|
||||||
use Egulias\EmailValidator\Tests\EmailValidator\Dummy\DummyReason;
|
use Egulias\EmailValidator\Tests\EmailValidator\Dummy\DummyReason;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class MultipleErrorsTest extends TestCase
|
class MultipleErrorsTest extends TestCase
|
||||||
{
|
{
|
||||||
@@ -35,4 +36,31 @@ class MultipleErrorsTest extends TestCase
|
|||||||
$this->assertEquals($expectedReason, $multiError->description());
|
$this->assertEquals($expectedReason, $multiError->description());
|
||||||
$this->assertEquals($error1, $multiError->reason());
|
$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]'],
|
||||||
['validipv4@127.0.0.0'],
|
['validipv4@127.0.0.0'],
|
||||||
['withhyphen@domain-exam.com'],
|
['withhyphen@domain-exam.com'],
|
||||||
|
['valid_long_domain@71846jnrsoj91yfhc18rkbrf90ue3onl8y46js38kae8inz0t1.5a-xdycuau.na49.le.example.com']
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user