mirror of
https://github.com/egulias/EmailValidator.git
synced 2026-08-20 10:20:34 +00:00
Fix PHP 7.4 support (#203)
Adding support for deprecated PHP behaviours.
This commit is contained in:
committed by
Eduardo Gulias Davis
parent
128cc721d7
commit
a6c8d7101b
@@ -9,6 +9,7 @@ php:
|
||||
- 7.1
|
||||
- 7.2
|
||||
- 7.3
|
||||
- 7.4snapshot
|
||||
|
||||
env:
|
||||
global:
|
||||
|
||||
@@ -77,10 +77,22 @@ class EmailLexer extends AbstractLexer
|
||||
|
||||
protected $previous;
|
||||
|
||||
private static $nullToken = [
|
||||
'value' => '',
|
||||
'type' => null,
|
||||
'position' => 0,
|
||||
];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->previous = $this->token = self::$nullToken;
|
||||
}
|
||||
|
||||
public function reset()
|
||||
{
|
||||
$this->hasInvalidTokens = false;
|
||||
parent::reset();
|
||||
$this->previous = $this->token = self::$nullToken;
|
||||
}
|
||||
|
||||
public function hasInvalidTokens()
|
||||
@@ -122,8 +134,10 @@ class EmailLexer extends AbstractLexer
|
||||
public function moveNext()
|
||||
{
|
||||
$this->previous = $this->token;
|
||||
$hasNext = parent::moveNext();
|
||||
$this->token = $this->token ?: self::$nullToken;
|
||||
|
||||
return parent::moveNext();
|
||||
return $hasNext;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -184,7 +184,7 @@ class DomainPart extends Parser
|
||||
|
||||
$domain .= $this->lexer->token['value'];
|
||||
$this->lexer->moveNext();
|
||||
} while ($this->lexer->token);
|
||||
} while (null !== $this->lexer->token['type']);
|
||||
|
||||
return $domain;
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ class LocalPart extends Parser
|
||||
$closingQuote = false;
|
||||
$openedParenthesis = 0;
|
||||
|
||||
while ($this->lexer->token['type'] !== EmailLexer::S_AT && $this->lexer->token) {
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_DOT && !$this->lexer->getPrevious()) {
|
||||
while ($this->lexer->token['type'] !== EmailLexer::S_AT && null !== $this->lexer->token['type']) {
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_DOT && null === $this->lexer->getPrevious()['type']) {
|
||||
throw new DotAtStart();
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ class LocalPart extends Parser
|
||||
|
||||
$this->lexer->moveNext();
|
||||
|
||||
while ($this->lexer->token['type'] !== EmailLexer::S_DQUOTE && $this->lexer->token) {
|
||||
while ($this->lexer->token['type'] !== EmailLexer::S_DQUOTE && null !== $this->lexer->token['type']) {
|
||||
$parseAgain = false;
|
||||
if (isset($special[$this->lexer->token['type']]) && $setSpecialsWarning) {
|
||||
$this->warnings[CFWSWithFWS::CODE] = new CFWSWithFWS();
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Egulias\Tests\EmailValidator\Validation;
|
||||
|
||||
use Egulias\EmailValidator\EmailLexer;
|
||||
use Egulias\EmailValidator\EmailValidator;
|
||||
use Egulias\EmailValidator\Exception\CommaInDomain;
|
||||
use Egulias\EmailValidator\Exception\NoDomainPart;
|
||||
@@ -17,7 +18,7 @@ class MultipleValidationWithAndTest extends TestCase
|
||||
{
|
||||
public function testUsesAndLogicalOperation()
|
||||
{
|
||||
$lexer = $this->getMockBuilder("Egulias\\EmailValidator\\EmailLexer")->getMock();
|
||||
$lexer = new EmailLexer();
|
||||
$validationTrue = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
|
||||
$validationTrue->expects($this->any())->method("isValid")->willReturn(true);
|
||||
$validationTrue->expects($this->any())->method("getWarnings")->willReturn([]);
|
||||
@@ -38,7 +39,7 @@ class MultipleValidationWithAndTest extends TestCase
|
||||
|
||||
public function testValidationIsValid()
|
||||
{
|
||||
$lexer = $this->getMockBuilder("Egulias\\EmailValidator\\EmailLexer")->getMock();
|
||||
$lexer = new EmailLexer();
|
||||
|
||||
$validation = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
|
||||
$validation->expects($this->any())->method("isValid")->willReturn(true);
|
||||
@@ -59,7 +60,7 @@ class MultipleValidationWithAndTest extends TestCase
|
||||
];
|
||||
$expectedResult = array_merge($warnings1, $warnings2);
|
||||
|
||||
$lexer = $this->getMockBuilder("Egulias\\EmailValidator\\EmailLexer")->getMock();
|
||||
$lexer = new EmailLexer();
|
||||
$validation1 = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
|
||||
$validation1->expects($this->any())->method("isValid")->willReturn(true);
|
||||
$validation1->expects($this->once())->method("getWarnings")->willReturn($warnings1);
|
||||
@@ -81,7 +82,7 @@ class MultipleValidationWithAndTest extends TestCase
|
||||
|
||||
$expectedResult = new MultipleErrors([$error1, $error2]);
|
||||
|
||||
$lexer = $this->getMockBuilder("Egulias\\EmailValidator\\EmailLexer")->getMock();
|
||||
$lexer = new EmailLexer();
|
||||
|
||||
$validation1 = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
|
||||
$validation1->expects($this->once())->method("isValid")->willReturn(false);
|
||||
@@ -105,7 +106,7 @@ class MultipleValidationWithAndTest extends TestCase
|
||||
|
||||
$expectedResult = new MultipleErrors([$error1]);
|
||||
|
||||
$lexer = $this->getMockBuilder("Egulias\\EmailValidator\\EmailLexer")->getMock();
|
||||
$lexer = new EmailLexer();
|
||||
|
||||
$validation1 = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
|
||||
$validation1->expects($this->any())->method("isValid")->willReturn(false);
|
||||
@@ -128,7 +129,7 @@ class MultipleValidationWithAndTest extends TestCase
|
||||
|
||||
$expectedResult = new MultipleErrors([$error]);
|
||||
|
||||
$lexer = $this->getMockBuilder("Egulias\\EmailValidator\\EmailLexer")->getMock();
|
||||
$lexer = new EmailLexer();
|
||||
|
||||
$validation1 = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
|
||||
$validation1->expects($this->any())->method("isValid")->willReturn(false);
|
||||
@@ -147,7 +148,7 @@ class MultipleValidationWithAndTest extends TestCase
|
||||
|
||||
public function testBreakoutOnInvalidEmail()
|
||||
{
|
||||
$lexer = $this->getMockBuilder("Egulias\\EmailValidator\\EmailLexer")->getMock();
|
||||
$lexer = new EmailLexer();
|
||||
|
||||
$validationNotCalled = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
|
||||
$validationNotCalled->expects($this->never())->method("isValid");
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
"require-dev" : {
|
||||
"satooshi/php-coveralls": "^1.0.1",
|
||||
"phpunit/phpunit": "^4.8.35||^5.7||^6.0",
|
||||
"symfony/phpunit-bridge": "^4.4@dev",
|
||||
"dominicsayers/isemail": "dev-master"
|
||||
},
|
||||
"suggest": {
|
||||
|
||||
+7
-4
@@ -8,7 +8,6 @@
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false"
|
||||
syntaxCheck="false"
|
||||
bootstrap="vendor/autoload.php"
|
||||
>
|
||||
<testsuites>
|
||||
@@ -19,8 +18,12 @@
|
||||
</testsuites>
|
||||
|
||||
<filter>
|
||||
<blacklist>
|
||||
<directory>./vendor</directory>
|
||||
</blacklist>
|
||||
<whitelist>
|
||||
<directory>./EmailValidator/</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
|
||||
<listeners>
|
||||
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
|
||||
</listeners>
|
||||
</phpunit>
|
||||
|
||||
Reference in New Issue
Block a user