New in Symfony 6.2: Better Debugging Commands
November 15, 2022 • Published by Javier Eguiluz
Symfony 6.2 is backed by:
Warning: This post is about an unsupported Symfony version. Some of this information may be out of date. Read the most recent Symfony Docs.
Symfony includes many commands to help you debug issues in your applications while developing them. In Symfony 6.2 we're improving some of those commands and adding new ones.
New Command to Count Pending Messages
A useful metric to know when working with the Messenger component is the
number of queued messages pending to be processed. In Symfony 6.2 we're adding a
new messenger:stats
command to show you that:
1 2 3 4 5
# displays the number of queued messages in all transports
$ php bin/console messenger:stats
# shows stats only for some transports
$ php bin/console messenger:stats my_transport_name other_transport_name
Improved Config Debug
The debug:config
displays by default the placeholders of env vars instead of
their actual values. For example:
1 2
$ php bin/console debug:config framework secret
secret: '%env(APP_SECRET)%'
In Symfony 6.2 we're adding a new --resolve-env
option to that command to
display the actual value the env vars:
1 2
$ php bin/console debug:config framework --resolve-env secret
secret: 90d83502629d64dec4cd6e33c9b31267
Improved Env Var Debug
In Symfony 6.2, the debug:dotenv
command adds a new optional argument to
only display the variables whose names match fully or partially the given string:
1 2 3 4 5 6 7 8 9
$ php bin/console debug:dotenv AWS
// ...
---------------------- -------------------------------------
Variable Value
---------------------- -------------------------------------
AWS_ACCESS_KEY_ID ...
AWS_SECRET_ACCESS_KEY ...
AWS_DEFAULT_REGION ...
...
New Mailer Test Command
A common need when working with emails is to test if a given mailer works properly.
The easiest way to do that is to send an actual test email through that mailer.
That's why in Symfony 6.2 we're adding a new mailer:test
command:
1 2 3 4 5 6 7 8 9
# the only required argument is the TO address
$ php bin/console mailer:test someone@example.com
# you can customize the FROM address, subject, body and transport name
$ php bin/console mailer:test someone@example.com
--from=testing@example.com
--subject="New test to check if email works"
--body="Lorem ipsum dolor sit amet"
--transport=the-transport-name
You can't use features such as file attachments because the purpose of the command is just to test if a certain transport works (i.e. is properly configured). Also, note that this command bypasses the Messenger bus (if configured) to ease testing even when the messenger consumer is not running.
Help the Symfony project!
As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.
Comments are closed.
To ensure that comments stay relevant, they are closed for old posts.
Note that in the example, grep is not necessary as the command accepts the config path as 2nd argument.
$ bin/console debug:config framework secret --resolve-env