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

Skip to content

[AssetMapper] Asset install fails due to mocked HTTP client #58149

Open
@Jean85

Description

@Jean85

Symfony version(s) affected

6.4.10

Description

I'm migrating my Symfony 6.4 app from Webpack Encore to AssetMapper, but I'm having an issue with the installation of the assets.

The importmap:install requires the HTTP client to download assets; since it's using the normal client from the app itself, it may encounter issues if the client is altered in any way.

In my case, I set APP_ENV=test from the start in my CI, so that every command runs with that environment, even the cache:clear and importmap:install post-install command executed during composer install; in said environment, I also mocked the HTTP client, which in turn means that importmap:install tries to execute HTTP calls with such mocked client, which during the vendor installation is obviously not ready.

How to reproduce

  • require symfony/asset-mapper in a Symfony skeleton app
  • require some remote asset (i.e. bin/console importmap:require jquery)
  • set the HTTP client to use a "broken" mocked response factory:
namespace Foo;

class MockClientCallback
{
    public function __invoke()
    {
        throw new \Exception('Intentional failure');
    }
}
framework:
 http_client:
   mock_response_factory: Foo\MockClientCallback
  • run bin/console importmap:install

Possible Solution

I don't know how to limit the scope of the mock factory. Using a scoped client for the assets would not fix my issue; maybe we shouldn't use the client from the app for such a command?

Additional Context

#49995 & #52257 reported an issue with the same root cause, and #52265 tried to solve it but seems stuck.

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