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

[DI] Fix FactoryReturnTypePassTest on PHP 5 #29949

Closed

Conversation

przemyslaw-bogusz
Copy link
Contributor

Q A
Branch? 3.4
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT
Doc PR

One of my PRs failed a Travis CI test on PHP 5 due to a syntax error resulting from loading a class with return type declarations:
https://travis-ci.org/symfony/symfony/jobs/482202091#L2865-L2867

Since FactoryReturnTypePass works only PHP 7

public function process(ContainerBuilder $container)
{
// works only since php 7.0 and hhvm 3.11
if (!method_exists(\ReflectionMethod::class, 'getReturnType')) {
return;
}

I modified FactoryReturnTypePassTest accordingly.

@@ -44,13 +45,8 @@ public function testProcess()
$pass = new FactoryReturnTypePass();
$pass->process($container);

if (method_exists(\ReflectionMethod::class, 'getReturnType')) {
Copy link
Member

Choose a reason for hiding this comment

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

Seeing this change it looks like the test was expected to pass on older PHP versions too. And since the test doesn't fail always we should probably rather investigate why they sometimes fail and why they pass under other circumstances.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes there is an if/else clause in the 3.4 branch, however a few lines above that, there is reference to FactoryDummy fixture, that causes the syntax (parse) error, because it does not have a valid PHP 5 syntax:

$factory->setFactory([FactoryDummy::class, 'createFactory']);

AppVeyor CI test also points out the same issue:
https://ci.appveyor.com/project/fabpot/symfony/builds/21760919?fullLog=true#L2048
Anyway, what can I do to help solve this issue? If there is an issue, to begin with ...

@nicolas-grekas
Copy link
Member

This did work before, and this file didn't change recently. I think this change is wrong and that there is an issue in #29944 instead: yes, the referenced factory class is PHP7-only. BUT service/factory classes shouldn't be loaded unless needed. That's what I would look for in #29944: why does it force loading the class now?

@przemyslaw-bogusz
Copy link
Contributor Author

You mean that #29944 is forcing FactoryReturnTypePassTest to be loaded, or forcing the test to load FactoryDummy?

@nicolas-grekas nicolas-grekas added this to the 3.4 milestone Jan 30, 2019
@nicolas-grekas
Copy link
Member

Closing as if there is anything to change here (right now I don't think so), it should be done in #29944

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants