- The test suites should run all the functionality, you can run the
composer test
command to run the entire test suite as well asphpstan
. - codestyles can be tested and fixed by
composer cs:check
&composer cs:fix
- I have updated the minimum php dependency to 8.2 I wanted to make use of constructor property promotion
- I have used
pest
testing framework for writing the tests. tests include functional and unit suites, they also cover database testing.
We want to build a service which will take a request.json
and:
- Process the file and create two separate collections for
Fruits
andVegetables
- Each collection has methods like
add()
,remove()
,list()
; - Units have to be stored as grams;
- Store the collections in a storage engine of your choice. (e.g. Database, In-memory)
- Provide an API endpoint to query the collections. As a bonus, this endpoint can accept filters to be applied to the returning collection.
- Provide another API endpoint to add new items to the collections (i.e., your storage engine).
- As a bonus you might:
- consider giving option to decide which units are returned (kilograms/grams);
- how to implement
search()
method collections; - use latest version of Symfony's to embbed your logic
You have two ways of moving on:
- You call the Service from PHPUnit test like it's done in dummy test (just run
bin/phpunit
from the console)
or
- You create a Controller which will be calling the service with a json payload
- Keep KISS, DRY, YAGNI, SOLID principles in mind
- Timebox your work - we expect that you would spend between 3 and 4 hours.
- Your code should be tested
- Please upload your code to a public git repository (i.e. GitHub, Gitlab)
Optional. Just here if you want to run it isolated.
docker pull tturkowski/fruits-and-vegetables
docker build -t tturkowski/fruits-and-vegetables -f docker/Dockerfile .
docker run -it -w/app -v$(pwd):/app tturkowski/fruits-and-vegetables sh
docker run -it -w/app -v$(pwd):/app tturkowski/fruits-and-vegetables bin/phpunit
docker run -it -w/app -v$(pwd):/app -p8080:8080 tturkowski/fruits-and-vegetables php -S 0.0.0.0:8080 -t /app/public
# Open http://127.0.0.1:8080 in your browser