How to get composer to suggest users to install a dependency as a dev dependency

2024-01-15 / php.watch

Last week I was installing a mocking framework with Composer and got the following prompt:

$ composer require mockery/mockery
mockery/mockery is currently present in the require-dev key and you ran the command without the --dev flag, which will move it to the require key.
Do you want to move this requirement? [no]?

How cool! I didn't know you could hint Composer to suggest a dependency to be installed as a testing dependency.

After further inspection, Composer determines this based on the tags used for the package

If you add dev, testing, or static analysis keywords to your package's composer.json, Composer will prompt users to install it as a dev dependency.

{
"name": "spatie/tabular-assertions",
"keywords": ["testing"]
}