/booking-tdd-demo

Look, no Mocks! Functional TDD with PHP

Primary LanguagePHPMIT LicenseMIT

Booking Demo; functional TDD attempt

Work in progress..

Build Status Scrutinizer Code Quality

Challenge

  • Decoupling decisions from effects

    Solution: The world is impure. Instead, we strive towards implementing as much of our code base as pure functions, so that an application is impure only at its boundaries. Using functional composition with monads, we can succinctly conditionally compose from pure and impure functions.

    Benefits: Pure functions only makes a decision based on input, and returns information about this decision as output, so is easy to unit test. Impure functions are used as humble functions that you may don't need to unit test. Impure functions can call pure functions, so at the boundary, an application must gather impure data, and use it to call pure functions. This automatically leads to the ports and adapters architecture.

Requirements

To run this application, you will need:

Installation

composer install
composer sqlite

Usage

composer serve

Example request

curl -X POST http://localhost/reservations/ \
 -H 'Content-Type: application/json' \
 -d '{"date": "Y-m-d H:i:s", "name": "Some name", "email": "Some email", "quantity": 1}'