The inventory

Exercise 1 of 6 in chapter 11 · 260 XP · 5 objectives checked by tests

Topics covered: Console command#[AsCommand]SymfonyStyle#[Option]Exit codesCommandTester

Every morning, Gorm takes the inventory with a scroll in hand, copying the menu out dish by dish. He would like to type one command and see everything at once: the dishes, their category, their price and the portions left.

Console commands

A command is a class marked #[AsCommand], whose __invoke() method does the work. Like a controller, it receives its services through autowiring. Its options and arguments are declared directly as parameters of __invoke().

SymfonyStyle ($io) gives a neat, consistent output: title(), table(), success(), warning(), error()…

A command returns an exit code: Command::SUCCESS (0), Command::FAILURE (1) or Command::INVALID (2). A script, a scheduled task or the CI rely on it to know whether everything went well.

Your mission

Write app:inventaire (the inventory):

  1. a title, “Menu inventory”, then a table with the columns Dish, Category, Price (12.50 gp) and Portions;
  2. in menu order: categories by position, then from cheapest to most expensive;
  3. the --categorie=Drinks option (categorie = category) shows a single category;
  4. an unknown category makes the command fail, with The category "Desserts" does not exist.;
  5. a final summary: 5 dishes on the menu. (1 dish in the singular), or The menu is empty. if there is nothing.

Try it in the Console tab: app:inventaire, then app:inventaire --categorie=Drinks.