Chapter 11 of the Symfony for PHP developers track
The boss's orders
6 exercises · 1,700 XP · about 4 h
Console command#[AsCommand]SymfonyStyle#[Option]Exit codesCommandTester#[Argument]Boolean optionsValidatorInterfaceCommand::INVALIDInteractive mode#[Ask]#[Interact]$io->choice()$io->confirm()--no-interactionLong-running taskprogressIterate()--dry-runBatch processingtoIterable()VerbosityDebuggingNon-interactive mode
The chapter's exercises
-
The inventory
Exercise 1 · 260 XP · 5 objectives checked by tests
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 command#[AsCommand]SymfonyStyle#[Option]Exit codesCommandTester
-
Bruna's command
Exercise 2 · 270 XP · 5 objectives checked by tests
Bruna invents her dishes late at night, when the dining room is closed. Rather than opening the kitchen form, she would like to add them in a single line:
#[Argument]#[Option]Boolean optionsValidatorInterfaceCommand::INVALID
-
Gorm asks the questions
Exercise 3 · 270 XP · 5 objectives checked by tests
Gorm wants to add dishes from the command line too. But he never remembers the order of the arguments, nor the exact names of the categories. He would like to type app:plat:ajouter, and nothing else, and have the command ask him the questions.
Interactive mode#[Ask]#[Interact]$io->choice()$io->confirm()--no-interaction
-
The big clean-up
Exercise 4 · 280 XP · 5 objectives checked by tests
The reservation book keeps growing. Reservations honored or canceled months ago pile up in it, and the reservation book page is slowing down. Gorm wants a big clean-up command, to run once a month (and one day, through a scheduled task).
Long-running taskprogressIterate()--dry-runBatch processingtoIterable()Verbosity
-
Testing the orders
Exercise 5 · 280 XP · 5 objectives checked by tests
The big clean-up works. But a command that deletes data, run every month without anyone watching it, is exactly the kind of code you want to be sure of. The day Pippin “simplifies” it, the tests will have to scream.
-
🐉 Boss: orders misunderstood
Exercise 6 · 340 XP · 5 objectives checked by tests
Pippin went over the tavern's commands to make them “more careful”. Since then:
DebuggingConsole commandExit codesNon-interactive modeBatch processing