Skip to content
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

TokensAnalyzer::isConstantInvocation - various fixes #5685

Closed
wants to merge 4 commits into from
Closed

TokensAnalyzer::isConstantInvocation - various fixes #5685

wants to merge 4 commits into from

Conversation

kubawerlos
Copy link
Contributor

Fixes #5684

@kubawerlos kubawerlos changed the base branch from 3.0 to 2.19 May 5, 2021 13:25
@coveralls
Copy link

coveralls commented May 5, 2021

Coverage Status

Coverage increased (+0.003%) to 91.553% when pulling 6457088 on kubawerlos:fix_NativeConstantInvocationFixer into f196ab0 on FriendsOfPHP:2.19.

@kubawerlos kubawerlos changed the title NativeConstantInvocationFixer - fix for non-capturing catches TokensAnalyzer::isConstantInvocation - fix for non-capturing catches May 5, 2021
@kubawerlos kubawerlos added this to the 2.19.1 milestone May 5, 2021
@kubawerlos kubawerlos marked this pull request as ready for review May 5, 2021 15:14
keradus added a commit that referenced this pull request May 13, 2021
This PR was squashed before being merged into the 2.19 branch.

Discussion
----------

Calculate code coverage on PHP 8

It's almost a half a year since the release, we can use PHP 8 to calculate code coverage e.g. to avoid situation like in #5685 where it shows that coverage dropped.

Commits
-------

acc1806 Calculate code coverage on PHP 8
}
}

public function provideIsConstantInvocationCases()
{
return [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

converting array to yielding just for sake of change the approach is making diff longer, review more tricky, and increases the chances for conflict while syncing this change into multiple lines. please avoid in future

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

converting array to yielding just for sake of change

what about converting array to yielding for avoid code quadruplication?
Look at testIsConstantInvocation, testIsConstantInvocation70 and testIsConstantInvocation71 - exactly the same function content and in this fix, 4th copy - for PHP 8 - needs to be added. Also I want add assertion that all string tokens are checked to make it easier to read.

making diff longer, review more tricky

it is a burden someone has to bear, cleaning this up wasn't fun either.

increases the chances for conflict while syncing this change into multiple lines

how come? only changes for this file between 2.19 and 3.0 branches are migration rules.

* @param string $source
*
* @dataProvider provideIsConstantInvocation70Cases
* @requires PHP 7.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👎

with original code, we got nice skipped test message.
now, we don't even know that some test got skipped, as it was never generated

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please recover the original way, it will also save a lot of conflicts while merging 2.19 <> 3.0

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with original code, we got nice skipped test message.

what is nice about those messages? Running on PHP 8 182 are skipped, do you track them and verify if that number changes? it was always unnecessary noise to me

My reasoning is that data provider should provide test cases, and there is nothing wrong if it provides ones filtered for given PHP version.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @keradus here. I think it's better to have a feedback about skipped tests. Otherwise, if some are skipped for wrong reasons, you won't notice it. IMO test cases generation logic should be avoided as much as possible in data providers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did anyone ever benefit from those skipped tests messages?

The tests might always be skipped for wrong reasons, skipping them over if conditions in data provider won't save from it.

Copy link
Member

@keradus keradus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as commented

@julienfalque
Copy link
Member

As spotted by @GrahamCampbell in #5720, union types in non-capturing catches were still considered constant usage, I allowed myself to push a fix here.

@julienfalque
Copy link
Member

Added another fix for PHP 8 attributes.

static::assertSame(
$expectedValue,
$tokensAnalyzer->isConstantInvocation($index),
sprintf('Token at index '.$index.' should match the expected value (%s).', $expectedValue ? 'true' : 'false')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you use sprintf please add all vars (including $index) as arguments :)

[18 => false],
],
yield [
'<?php #[Foo] function foo() {}',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add '<?php #[\Foo] function foo() {}', , '<?php #[\A\Foo] function foo() {}' and '<?php #[A\Foo] function foo() {}',

@julienfalque julienfalque changed the title TokensAnalyzer::isConstantInvocation - fix for non-capturing catches TokensAnalyzer::isConstantInvocation - various fixes May 25, 2021
@kubawerlos
Copy link
Contributor Author

I'm not willing to make 4th copy of a function only to have some tests skipped in different PHP versions as those skipped message never gave any benefit.

@kubawerlos kubawerlos closed this May 25, 2021
@kubawerlos kubawerlos removed this from the 2.19.1 milestone May 25, 2021
@keradus
Copy link
Member

keradus commented Jun 4, 2021

benefit may not be the message, but the fact that test was skipped.
you may think that code work because all tests are 100% passing. but you run on PPH 7.1 and you would be not aware that you didn't run half of the tests.

keradus added a commit that referenced this pull request Jun 4, 2021
This PR was merged into the 2.19 branch.

Discussion
----------

Fix constant invocation detection cases

Replaces #5685.

/cc `@kubawerlos` I kept your authorship if you don't mind.

Commits
-------

d52875d Fix constant invocation detection cases
@kubawerlos kubawerlos deleted the fix_NativeConstantInvocationFixer branch June 9, 2021 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

native_constant_invocation applies to catch section without variables
7 participants