Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
Closed
@sylfabre

Description

@sylfabre
Issue body actions

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.