Skip to content

Latest commit

 

History

History
139 lines (129 loc) · 4.69 KB

README.md

File metadata and controls

139 lines (129 loc) · 4.69 KB

vending-machine

Requirements

Examples in this repo

  • No Framework
  • DDD (Domain Driver Design)
  • Dependency injection and container with PHP-DI
  • CommandBus and CommandQuery with Tactician
  • Implement DomainEvents
  • Implement Subscriber to update vending machine status
  • Implement Middleware to dispatch and persist domain events
  • Simple EventStore (var/log/domain_events.log)
  • Unit testing with PHPUnit
  • Simple Repository with json file and serialize entity with json-serializer
  • CLI with Symfony console

Project folder structure

.
├── app
│   └── config
├── bin
├── docker
│   └── php
├── src
│   ├── Application
│   │   ├── Catalog
│   │   │   └── Subscriber
│   │   ├── VendingMachine
│   │   │   ├── Command
│   │   │   ├── Request
│   │   │   └── Response
│   │   └── Wallet
│   │       └── Subscriber
│   ├── Domain
│   │   ├── Catalog
│   │   │   ├── Event
│   │   │   ├── Exception
│   │   │   └── Product
│   │   ├── Core
│   │   │   └── Event
│   │   │       └── Repository
│   │   ├── VendingMachine
│   │   │   ├── Event
│   │   │   ├── Exception
│   │   │   ├── Repository
│   │   │   └── Status
│   │   └── Wallet
│   │       ├── Coin
│   │       ├── Event
│   │       └── Exception
│   └── Infrastructure
│       ├── Repository
│       ├── Service
│       │   ├── Bus
│       │   │   └── Middleware
│       │   ├── Event
│       │   ├── File
│       │   └── Serialize
│       └── Ui
│           └── Cli
├── tests
│   └── unit
│       └── Application
│           └── VendingMachine
└── var
    ├── data
    └── log

Installation

Clone this repository

$ git clone git@github.com:albertcolom/vendor-machine.git

Start docker compose

$ docker-compose up -d

CLI

$ docker-compose exec php bin/console

Available commands

vending-machine
    vending-machine:coin:add       Add coin into the machine
    vending-machine:coin:add:user  User add coin into the machine
    vending-machine:coin:refund    Refund user coins
    vending-machine:create         Create vending machine with catalog and wallet
    vending-machine:create:empty   Create empty vending machine
    vending-machine:product:add    Add product into the machine
    vending-machine:product:buy    Buy product
    vending-machine:summary        Vending machine summary

Example commands with parameters

$ docker-compose exec php bin/console vending-machine:coin:add 0.1
$ docker-compose exec php bin/console vending-machine:coin:add:user 0.1
$ docker-compose exec php bin/console vending-machine:coin:refund
$ docker-compose exec php bin/console vending-machine:create
$ docker-compose exec php bin/console vending-machine:create:empty
$ docker-compose exec php bin/console vending-machine:product:add water 1
$ docker-compose exec php bin/console vending-machine:product:buy water
$ docker-compose exec php bin/console vending-machine:summary

Read live file event log

$ docker-compose exec php tail -f var/log/domain_events.log

Sample Output

[2020-07-12 19:03:09] "CoinAmountWasCreated" {"coin_type":0.05,"quantity":1}
[2020-07-12 19:03:09] "CoinAmountWasCreated" {"coin_type":0.1,"quantity":1}
[2020-07-12 19:03:09] "CoinAmountWasCreated" {"coin_type":1,"quantity":1}
[2020-07-12 21:20:25] "ProductLineWasCreated" {"product_type":"water","price":1,"quantity":1}
[2020-07-12 21:40:01] "CoinAmountWasRemoved" {"coin_type":1,"quantity":3}
[2020-07-12 21:40:01] "ProductLineWasRemoved" {"product_type":"juice","price":1,"quantity":1}

Test

$ docker-compose exec php bin/phpunit

Screenshots

  • Success message:

Success

  • Error message:

Error

  • Vending machine summary:

Summary