-
-
Notifications
You must be signed in to change notification settings - Fork 212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix PHP 7.4 support #203
Fix PHP 7.4 support #203
Conversation
Ready. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @nicolas-grekas , thanks for the update.
I have left some comments for you.
</filter> | ||
|
||
<listeners> | ||
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind explaining why is this listener needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because PHP 7.4 introduces new deprecations that affect phpunit, and the listener allows silencing them
EmailValidator/EmailLexer.php
Outdated
@@ -77,10 +77,16 @@ class EmailLexer extends AbstractLexer | |||
|
|||
protected $previous; | |||
|
|||
public function __construct() | |||
{ | |||
$this->reset(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling reset
on construction sounds a bit odd, reseting something 'new'. For what I've seen in the rest of the changes, this is needed mainly to do the equality evaluation (e.g https://github.com/egulias/EmailValidator/pull/203/files#diff-c759db088d5c729c1f537d85c2ea93d0R187).
I would suggest something like init()
:
$this->hasInvalidTokens = false;
$this->previous = $this->token = ['type' => null, 'value' => '', 'position' => 0];
and call that from both __contruct
& reset
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the code is full of checks with $this->lexer->token['type']
, when $this->lexer->token
is null
actually. PHP 7.4 is now refusing to access keys on null values, so that the affected properties must be set to an array representing the null-state. reset does it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation, understood. My suggestion is moving both lines to a new method so they can call it having a more expresive meaning and avoiding coupling too much construction with re-use (reseting to analyse another string).
__construct()
{
$this->init();
}
reset()
{
...
$this->init();
}
EmailValidator/EmailLexer.php
Outdated
public function reset() | ||
{ | ||
$this->hasInvalidTokens = false; | ||
parent::reset(); | ||
$this->previous = $this->token = ['type' => null, 'value' => '', 'position' => 0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest to use EmailLexer::C_NUL
for type
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this wouldn't be the same - we don't want to this be confused with the NUL char.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree. Should a new token be added?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so, null
is really the best "const" for this to me.
@@ -59,7 +60,7 @@ public function testAccumulatesWarnings() | |||
]; | |||
$expectedResult = array_merge($warnings1, $warnings2); | |||
|
|||
$lexer = $this->getMockBuilder("Egulias\\EmailValidator\\EmailLexer")->getMock(); | |||
$lexer = new EmailLexer(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
EmailValidator/EmailLexer.php
Outdated
@@ -122,8 +128,10 @@ public function getPrevious() | |||
public function moveNext() | |||
{ | |||
$this->previous = $this->token; | |||
$hasNext = parent::moveNext(); | |||
$this->token = $this->token ?: ['type' => null, 'value' => '', 'position' => 0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this line because of the lexer reaching the last token and being set to null
?
I'd suggest to express that case with something like
public function moveNext()
{
$this->previous = $this->token;
$hasNext = parent::moveNext();
/* new stuff */ $this->setEndToken($hasNext);
return $hasNext;
}
private function setFinalToken($nextToken)
{
$this->token = $this->token ?: ['type' => C_NUL, 'value' => '', 'position' => 0];
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're right about the reason: $this->token cannot be null.
not sure I get what the additional method would provide thought :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To understood this line I had to review carefully the full PR and take my time, even with my knowledge of the library.
The additional method adds clarity on the reason behind.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed a variant, does it solve the concern?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it can work.
Thanks!
Is this really the way to go about this @nicolas-grekas ?? |
@SamMousa you must be confused, this added dev dep is not to make Symfony's tests pass, but about making this very package tests pass. |
I have just removed it locally, the test listener and the dependency, and tests still pass. Note: that's on PHUnit 6. |
Try again with PHP7.4 + |
root@ba1517249f5f:/project# php --version
PHP 7.4.0alpha3 (cli) (built: Jul 12 2019 21:26:03) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0-dev, Copyright (c) Zend Technologies
PHPUnit 6.5.14 by Sebastian Bergmann and contributors.
............................................................... 63 / 253 ( 24%)
............................................................... 126 / 253 ( 49%)
............................................................... 189 / 253 ( 74%)
...........................................................SSSS 252 / 253 ( 99%)
. 253 / 253 (100%)
Time: 537 ms, Memory: 6.00MB
OK, but incomplete, skipped, or risky tests!
Tests: 253, Assertions: 351, Skipped: 4. |
Works for me:
```bash
root@ba1517249f5f:/project# php --version
PHP 7.4.0alpha3 (cli) (built: Jul 12 2019 21:26:03) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0-dev, Copyright (c) Zend Technologies
PHPUnit 6.5.14 by Sebastian Bergmann and contributors.
............................................................... 63 / 253 (
24%)
............................................................... 126 / 253 (
49%)
............................................................... 189 / 253 (
74%)
...........................................................SSSS 252 / 253 (
99%)
. 253 / 253
(100%)
Time: 537 ms, Memory: 6.00MB
OK, but incomplete, skipped, or risky tests!
Tests: 253, Assertions: 351, Skipped: 4.
```
…On Mon, Jul 22, 2019 at 5:27 PM Nicolas Grekas ***@***.***> wrote:
Try again with PHP7.4 + latest phpunit.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#203?email_source=notifications&email_token=AAEFRTM3SLOTEO64T7MYOILQAXGXZA5CNFSM4IE4SWTKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD2QJO6A#issuecomment-513841016>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAEFRTPHZMIPFMQUDOIOHT3QAXGXZANCNFSM4IE4SWTA>
.
|
Oh that's good news, maybe related to the removed mocks? I suppose I
patched them after adding the bridge and didn't try removing it after. PR
welcome I suppose.
|
@egulias would you accept a similar pull request for version 1? |
Hi @mlocati |
Done: see #206 |
Symfony is going to need this to have green CI on PHP 7.4 :)