Create a Symfony bundle, that defines a console command and allows other Symfony bundles in the application to provide their own code that should run whenever this command is executed.
Provide two sample bundles to demonstrate the work of this application.
Using Symfony 5.3+ create a bundle called HelloCommandBundle. This bundle should provide a console command called hello:bundles
php app/console hello:bundles
Any other bundle installed in the same Symfony application should be able to add their own code for execution.
For the demonstration purposes create two bundles FooBundle and BarBundle.
FooBundle should provide the following code:
echo "Hello from Foo!";
BarBundle should provide the following code:
echo "Hi from Bar!";
Whenever a used runs php app/console hello:bundles
, the following output should be produced:
Hello from Foo!
Hi from Bar!
NB: The number of bundles willing to greet a user is not known. There could be a dozen, or none. Not all of the installed bundles may be willing to do something when hello command is executed. Provide other bundles a way to register their code only if they want to.
Implement detailed logging, so that after execution of php app/console hello:bundles
the application log file
will contain the following records (with actual time obviously):
[2016-01-29 09:08:31] Starting the group greetings...
[2016-01-29 09:08:32] Is Foo polite and welcoming today?
[2016-01-29 09:08:32] Hello from Foo!
[2016-01-29 09:08:32] Is Bar polite and welcoming today?
[2016-01-29 09:08:32] Hi from Bar!
[2016-01-29 09:08:32] All greetings completed.
Create a functional test for the hello:bundles
console command itself.
Create unit tests for all other code in the HelloBundle.
NB: FooBundle and BarBundle are just for the demo. You do not need to create any tests for them.
NB: Do not forget to write negative tests as well. A positive test checks if a function behaves as expected with its expected input. A negative test checks if a function behaves as expected when something goes wrong. An expected result in this case could be a thrown exception, or returned boolean
false
- as defined by the developer of the tested method.
- PHP8
- Symfony 5.3+
- PSR-12
- http://symfony.com/doc/current/contributing/code/standards.html
- All classes and methods should be documented with phpdoc, containing not only the list of parameters and their types, but also a short description of what is the intended purpose of this method or class.
After the task is completed, provide a link to the repository on GitHub or BitBucket.