This repository holds the source of a voucher service. A small demo for a service application written in PHP 7.4 and Symfony 5 using Doctrine and Messenger Component to generate vouchers for orders.
For correct working inside the project, please note following dependencies:
- Infrastructure:
- Dependent Services:
- Coding language:
- Framework and components:
- Code quality and test development:
Note: For more detailed dependencies take a look into the configurations:
- Docker Compose config:
docker-compose.yml
- Application Docker config:
app/Dockerfile
- Symfony application config:
app/composer.json
To get involved into the development of this project you need to get a local copy of this repository:
git clone git@github.com:bassix/voucher-service.git
cd voucher-service
Note: This project is based on the GitFlow branching model and workflow.
Before the application environment can be started we need to generate an environment specific configuration specially for local development:
./env.sh
Note: the .env
file holds the following main environment variables:
- The
HOST_UID
andHOST_GID
of your local user and this ID's are used inside the container to get access to the volumes with right permissions. - The
PHP_DATE_TIMEZONE
to configure the time zone the application is running. The most common isEurope/Berlin
. The default value is set toUTC
. - The
OPCACHE_VALIDATE_TIMESTAMPS
to activate1
or deactivate0
the opcache rebuild by each request. Set this to0
in development mode.
Now lets start the Docker Compose environment:
docker-compose up -d --build
Note: The current configuration is binding the local project as a volume into the container.
Install all relevant dependencies:
docker exec --user www-data app composer install --dev
The main part of this service is the Symfony application it self. Following process is the main part of the implementation:
Draw.io source: docs/process/order-voucher-service.drawio
All resources for the service application are located inside the app/
directory. To run the following commands, change to this location.
For a better development and testing of the functionality the app provides some helpful console commands:
-
Generate a fake order to get a voucher:
docker exec --user www-data app bin/console app:order-voucher:create
-
Generate an order message to get a voucher:
docker exec --user www-data app bin/console app:order-voucher:message
-
List all existing orders and vouchers:
docker exec --user www-data app bin/console app:order-voucher:list
By default, the database schema will be created by migration (or database fixtures located at mariadb/fixtures/voucher.sql
).
Alternative the Doctrine commands can be used to start with an empty database:
docker exec --user www-data app bin/console doctrine:database:create
docker exec --user www-data app bin/console make:migration
docker exec --user www-data app bin/console doctrine:migrations:migrate
Note: if something went horribly wrong, you can start from the ground up by recreating the whole database (all existing migrations should be deleted):
docker exec --user www-data app bin/console doctrine:database:drop --force
Note: Why ever, the SQLite connection isn't working :/ So please use this workaround:
docker exec --user www-data app bin/console doctrine:database:drop --force
docker exec --user www-data app bin/console doctrine:database:create
docker exec --user www-data app bin/phpunit
Run PHPUnit tests:
docker exec --user www-data app bin/phpunit
Run phpstan to make statical analyse of the code. (Level from 0 to 7, where 0 is the most loose, 7 is the strongest. 0 is default):
docker exec --user www-data app vendor/phpstan/phpstan/phpstan analyse --level 7
Run php-cs-fixer to fix errors in code (use --dry-run
option only to see errors):
docker exec --user www-data app vendor/friendsofphp/php-cs-fixer/php-cs-fixer fix
Documentation and constructor with more detailed information could be found at https://mlocati.github.io/php-cs-fixer-configurator.
This service is based on Symfony Flex. The following steps were performed to create the basic project and application structure.
Create a new project from the Symfony Flex recipe:
composer create-project symfony/skeleton app
Install Doctrine support via the orm Symfony pack, as well as the MakerBundle, which will help generate some code:
composer require symfony/orm-pack
After the entities were created the initial schema migration was generated:
docker exec --user www-data app bin/console doctrine:migrations:diff
The PHPUnit Testing Framework:
composer require --dev symfony/phpunit-bridge
PHPStan Symfony Framework extensions and rules:
composer require --dev phpstan/phpstan-symfony
PHP Coding Standards Fixer Symfony Framework extensions and rules:
composer require --dev friendsofphp/php-cs-fixer