Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Hexagonal Architecture

Hexagonal Architecture

Implementing Hexagonal architecture with PHP

Source code(check branches): https://github.com/cherifGsoul/php-hexagonal-architecture

Mohamed Cherif Bouchelaghem

December 26, 2020
Tweet

More Decks by Mohamed Cherif Bouchelaghem

Other Decks in Programming

Transcript

  1. Hexagonal Architecture: What is it? “Create your application to work

    without either a UI or a database so you can run automated regression-tests against the application, work when the database becomes unavailable, and link applications together without any user involvement.” Alistair Cockburn: Hexagonal architecture
  2. Hexagonal Architecture: What is it? Drawing from the the original

    article. Each facet of the hexagon represents a port (a technology-independent protocol capturing a reason for a discussion)
  3. Hexagonal Architecture: What is it? Ports, are abstractions on the

    boundaries. Adapters, are implementations of the given ports.
  4. Hexagonal Architecture: What is it? - Ports: Are abstraction defined

    by the application - Adapters: are the implementation of the ports (abstraction) that connect the application with the outside world. The outside world is anything that is not really important to solve the problem we trying to solve: Database, UI (Delivery mechanism), frameworks (Mobile, web, … etc)
  5. About unit tests A test is not a unit test

    if: - It talks to a database - It communicates across the network - It touches the file system - You have to do things to your environment to run it (eg, change config files, comment line) - Tests that do this are integration tests.
  6. Hexagonal architecture: Why? Allow an application to equally be driven

    by users, programs, automated test or batch scripts, and to be developed and tested in isolation from its eventual run-time devices and databases.
  7. About unit tests For isolation usually people talk about mocks,

    in reality mocks are one of the test doubles that help to run make unit tests: - Mock - Fake - Spy - Stub - Dummy
  8. Calculate product taxes - Product has a category - Every

    category of products has its own tax rate (.17) - The tax calculation is based on simple formula: Product base cost + (product base cost * category tax rate) Source Code