项目作者: albertcolom

项目描述 :
Vending machine kata
高级语言: PHP
项目地址: git://github.com/albertcolom/vendor-machine.git
创建时间: 2020-07-09T13:57:14Z
项目社区:https://github.com/albertcolom/vendor-machine

开源协议:

下载


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

  1. .
  2. ├── app
  3. └── config
  4. ├── bin
  5. ├── docker
  6. └── php
  7. ├── src
  8. ├── Application
  9. ├── Catalog
  10. └── Subscriber
  11. ├── VendingMachine
  12. ├── Command
  13. ├── Request
  14. └── Response
  15. └── Wallet
  16. └── Subscriber
  17. ├── Domain
  18. ├── Catalog
  19. ├── Event
  20. ├── Exception
  21. └── Product
  22. ├── Core
  23. └── Event
  24. └── Repository
  25. ├── VendingMachine
  26. ├── Event
  27. ├── Exception
  28. ├── Repository
  29. └── Status
  30. └── Wallet
  31. ├── Coin
  32. ├── Event
  33. └── Exception
  34. └── Infrastructure
  35. ├── Repository
  36. ├── Service
  37. ├── Bus
  38. └── Middleware
  39. ├── Event
  40. ├── File
  41. └── Serialize
  42. └── Ui
  43. └── Cli
  44. ├── tests
  45. └── unit
  46. └── Application
  47. └── VendingMachine
  48. └── var
  49. ├── data
  50. └── log

Installation

Clone this repository

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

Start docker compose

  1. $ docker-compose up -d

CLI

  1. $ docker-compose exec php bin/console

Available commands

  1. vending-machine
  2. vending-machine:coin:add Add coin into the machine
  3. vending-machine:coin:add:user User add coin into the machine
  4. vending-machine:coin:refund Refund user coins
  5. vending-machine:create Create vending machine with catalog and wallet
  6. vending-machine:create:empty Create empty vending machine
  7. vending-machine:product:add Add product into the machine
  8. vending-machine:product:buy Buy product
  9. vending-machine:summary Vending machine summary

Example commands with parameters

  1. $ docker-compose exec php bin/console vending-machine:coin:add 0.1
  2. $ docker-compose exec php bin/console vending-machine:coin:add:user 0.1
  3. $ docker-compose exec php bin/console vending-machine:coin:refund
  4. $ docker-compose exec php bin/console vending-machine:create
  5. $ docker-compose exec php bin/console vending-machine:create:empty
  6. $ docker-compose exec php bin/console vending-machine:product:add water 1
  7. $ docker-compose exec php bin/console vending-machine:product:buy water
  8. $ docker-compose exec php bin/console vending-machine:summary

Read live file event log

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

Sample Output

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

Test

  1. $ docker-compose exec php bin/phpunit

Screenshots

  • Success message:

Success

  • Error message:

Error

  • Vending machine summary:

Summary