I’ve recently built another open source testing tool. This time it’s for one of the main frameworks I’ve used for the past 5 years – Symfony 2/3. It’s called symfony-router-validation.

It comes with two components. The first is the Symfony command router:validate.

Running router:validate in an app

As you can see in the screenshot above, the command looked through all the routes in a Symfony app and reported the ones that were invalid.

You can use this in continuous integration testing or even a Git pre-commit hook, to make sure that no invalid routes get merged into the production code. The command returns exit code 1 if there is a problem, so one way to achieve this would be the following bash code:

#!/usr/bin/env bash

app/console router:validate # 'app/console' is for Symfony 2, or use 'bin/console' in Symfony 3.
if [[ $? != '0' ]]; then
    exit 1

If you want even more flexibility, a service is available from the service container, called amyboyd.router_validation, which you can use directly.

How to install

Add the package to your Composer dependencies:

composer require amyboyd/symfony-router-validation

Add these lines to your services configuration (e.g. in services.yml or config.yml):

        class: AmyBoyd\SymfonyStuff\RouterValidation\RouterValidationCommand
            -  { name: console.command }

        class: AmyBoyd\SymfonyStuff\RouterValidation\RouterValidationService
            controllerNameParser: '@controller_name_converter'
            container: '@service_container'

Now the library is installed and ready to use.

Here are some links with more information: