Code Monkey home page Code Monkey logo

bassix / voucher-service Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 1.0 227 KB

This is a small demo of a service application written in PHP 7.4 and Symfony 5 using Doctrine and Messenger Component to generate vouchers for orders.

License: MIT License

PHP 86.32% Dockerfile 5.36% Shell 1.27% TSQL 7.05%
php php7 php74 symfony symfony5 doctrine-orm doctrine2 rabittmq mariadb docker docker-compose phpstan doctrine phpunit phpunit-tests symfony-messenger

voucher-service's Introduction

Voucher service

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:

Note: For more detailed dependencies take a look into the configurations:

To get involved into the development of this project you need to get a local copy of this repository:

git clone [email protected]: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 and HOST_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 is Europe/Berlin. The default value is set to UTC.
  • The OPCACHE_VALIDATE_TIMESTAMPS to activate 1 or deactivate 0 the opcache rebuild by each request. Set this to 0 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

Voucher application

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.

Order a voucher

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

Doctrine

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

Code quality tools

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.

Service application creation

This service is based on Symfony Flex. The following steps were performed to create the basic project and application structure.

Create new Symfony application

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

Install code quality tools

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

voucher-service's People

Contributors

bassix avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

manishpparmar

voucher-service's Issues

We want to generate vouchers

The current voucher service should be able to generate vouchers for orders with a total amount of 100โ‚ฌ or more.

Processing order message is throwing an exception

The messenger is throwing an exception during the processing of the given order:

Error thrown while handling message App\Message\OrderMessage.
Sending for retry #2 using 2000 ms delay.
Error: "The EntityManager is closed." 
{"message":{"App\\Message\\OrderMessage":[]},"class":"App\\Message\\OrderMessage","retryCount":2,"delay":2000,"error":"The EntityManager is closed.","exception":"[object] (Symfony\\Component\\Messenger\\Exception\\HandlerFailedException(code: 0): The EntityManager is closed. at /srv/app/vendor/symfony/messenger/Middleware/HandleMessageMiddleware.php:80)
[previous exception] [object] (Doctrine\\ORM\\ORMException(code: 0): The EntityManager is closed. at /srv/app/vendor/doctrine/orm/lib/Doctrine/ORM/ORMException.php:146)"}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.