Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Dependency Injection] Make testing preloading possible in CI #54198

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

Closed
sylfabre opened this issue Mar 7, 2024 · 3 comments
Closed

[Dependency Injection] Make testing preloading possible in CI #54198

sylfabre opened this issue Mar 7, 2024 · 3 comments

Comments

@sylfabre
Copy link
Contributor

sylfabre commented Mar 7, 2024

Description

We recently upgraded to API Platform 2.7 at my company and faced a similar bug to api-platform/core#5522 but with this file: https://github.com/api-platform/core/blob/2.7/src/Symfony/Validator/EventListener/ValidationExceptionListener.php

I know that this is obsolete code and we should use API Platform v3 but that's not the point here 😊

The bug happens with preloading because the call to class_alias() is not wrapped within an if like this fix: https://github.com/api-platform/core/pull/5523/files

I know that bugs happen, that's life. But I looked for a way to test my application by enabling preloading in my CI ie in CLI mode.
As explained by the PHP documentation it is useless performance-wise but it may report issues with preloading we use in production in FPM mode.

A simple reproducer would be

# test.php
<?php
class Hello {}
class_alias(Hello::class, 'HelloAlias');

php --define opcache.preload=test.php --define opcache.enable_cli=1 test.php

It fails as expected with this message:

PHP Warning:  Cannot declare class HelloAlias, because the name is already in use in /var/www/assoconnect/test.php on line 3

However, the Symfony framework prevents me from testing my application because the preloading Symfony-generated file has an early return for CLI mode. It's defined here: https://github.com/symfony/symfony/blob/7.1/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php#L329

So I can't test my application with preloading in the CI to make sure it will work correctly in production with preloading.

A solution would be to remove the condition in PhpDumper but it was added 4 years ago to address an issue: #37353

A viable workaround for this issue is, if need be, moving the condition to a dedicated file which would include Symfony-generated preloading file

<?php
if ('cli' === PHP_SAPI) {
    return;
}
include [Symfony-generated preloading file]

And better ideas are welcome too!

Example

No response

@carsonbot
Copy link

Thank you for this suggestion.
There has not been a lot of activity here for a while. Would you still like to see this feature?
Every feature is developed by the community.
Perhaps someone would like to try?
You can read how to contribute to get started.

@carsonbot
Copy link

Could I get an answer? If I do not hear anything I will assume this issue is resolved or abandoned. Please get back to me <3

@carsonbot
Copy link

Hey,

I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen!

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

No branches or pull requests

3 participants