Skip to content
Latchkey

Symfony "Controller ... requires that you provide a value for the ... argument" in CI

Symfony's argument resolver could not produce a value for a controller action parameter, either because no route parameter, query value, or service matches it, or because a required entity was not found during a test request.

What this error means

A functional test using the test client fails with "Controller \"App\Controller\X::show()\" requires that you provide a value for the \"$id\" argument."

Symfony
RuntimeException: Controller "App\Controller\OrderController::show()" requires that you
provide a value for the "$order" argument. Either the argument is nullable and no value
was provided or you preceded the argument with a "?".

Common causes

A route parameter is missing in the test request

The test requested a URL that does not supply the placeholder the action needs, so the resolver has no value to inject.

A mapped entity was not found in the test database

With the MapEntity resolver, the id in the URL matches no row (the test fixtures were not loaded), so no entity can be injected into a non-nullable argument.

How to fix it

Request a URL that supplies the argument

  1. Generate the URL with the router so required parameters are present.
  2. Ensure any entity the action maps exists in the test database via fixtures.
  3. Make the argument nullable only if the action truly handles a missing value.
tests/Controller/OrderControllerTest.php
$url = $client->getContainer()->get('router')->generate('order_show', ['id' => 1]);
$client->request('GET', $url);

Load fixtures before the request

Seed the test database so a mapped entity for the requested id exists when the controller runs.

Terminal
php bin/console --env=test doctrine:fixtures:load --no-interaction

How to prevent it

  • Build request URLs with the router, not hard-coded strings, in tests.
  • Load fixtures for entities that controller actions map.
  • Mark arguments nullable only when the action genuinely supports a missing value.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →