Guillaume M.
Guillaume M.

Reputation: 21

How to run phpunit tests on Symfony 4?

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.

Upvotes: 2

Views: 1545

Answers (2)

Guillaume M.
Guillaume M.

Reputation: 21

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.

Upvotes: 0

Wouter J
Wouter J

Reputation: 41934

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 }

Upvotes: 1

Related Questions