2

When I try to run a functional test on Symfony 4, I get this:

The routing file "{__PATH__}config/routes/admin.yaml" contains unsupported keys for "admin_home": "controller". Expected one of: "resource", "type", "prefix", "path", "host", "schemes", "methods", "defaults", "requirements", "options", "condition", "ControllerTest"

I don't understand why because my routing configuration follows the official documentation:

admin_home:
    path: ''
    controller: App\Controller\Admin\HomeController::home

Official doc: http://symfony.com/doc/current/routing.html (in YAML tabs, I didn't install the annotations package). Where "controller" is a supported key.

I installed the PHPUnit package composer require --dev symfony/phpunit-bridge then I run ./vendor/bin/simple-phpunit.

4
  • Does bin/console debug:router show the route? And just for grins change the path to something like '/admin' Not sure what route does with an empty path though I don't think it is a problem. Double check your indenting. Commented Mar 14, 2018 at 21:50
  • Indeed, it doesn't work. I still don't understand why since I guess I was using these routing files before. Commented Mar 14, 2018 at 22:10
  • I checked indenting without success. It works if I move to the SF3 writing defaults: { _controller: App\Controller\Admin\HomeController::home } Commented Mar 14, 2018 at 22:12
  • And bin/console debug:router shows the same error? I honestly can't see a problem. Are you sure you are looking at the correct file? Maybe bring down a fresh skeleton and do nothing but add your route file. The error message is very strange indeed. Commented Mar 14, 2018 at 22:53

2 Answers 2

1

This is a new syntax, introduced in Symfony 3.4/4.0.

On older versions, you should use:

admin_home:
    path: ''
    defaults: { _controller: App\Controller\Admin\HomeController::home }
Sign up to request clarification or add additional context in comments.

3 Comments

What are the requirements? As said in the question, I'm using Symfony 4 "symfony/framework-bundle": "^4.0",
@GuillaumeM and symfony/routing ? (composer show symfony/routing)
versions : * v4.0.6. There is also a "conflicts" parts with 3 lines : symfony/config <3.4; symfony/dependency-injection <3.4, symfony/yaml <3.4. Is this an issue ?
0

As I could not reproduce the issue in a new project, even with the same composer.json file, I retried to remove the vendor directory.

It works.

2 Comments

Feel free to update this answer. I can't explain why this works while using composer commands did nothing.
Was this a fresh project to begin with or did you attempt to upgrade an existing older one? Composer is wonderful but sometimes updating between major versions can result in amusing issues. And sometimes just deleting the entire cache directory works like magic.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.