Awesome Open Source
Awesome Open Source

TDD Demo - ForumPHP 2020

Build Status

Live coding examples used during Forum PHP 2020 talk:

For a bit of theory, see 🇫🇷 De CRUD DDD, comment Meetic a sauv son legacy

Steps by step refactoring

⚠️ Warning : Only steps 1 & 2 are really considered bad. Next steps just show different testing styles.

  1. bad_implementation branch contains :
    • Architecture mistakes according to Hexagonal architecture (aka Port & Adapters)
    • Tests too much coupled with implementation details, and an incorrect usage of mocks
  2. bad_tests branch (see Pull Request) only fixes (some) hexagonal mistakes. Many obscure changes are required in the tests, proving they do not help much during refactoring
  3. integration_infra_medium_domain branch (see Pull Request) split tests this way:
    • Domain logic (Application/Domain folders): medium Unit tests, mocking only infrastructure
    • Technical logic (Infrastructure folder): integration tests for each specific technology
  4. integration_infra_medium_domain_wiremock branch (see Pull Request) only replaces Guzzle MockHandler with Wiremock, decoupling HTTP tests with the library being used for HTTP calls.
  5. integration_infra_medium_domain_no_di branch (see Pull Request) removes Dependency Injection Container usage and manually build tested classes instead.
  6. integration_infra_sociable branch (see Pull Request) replaces medium sized tests with Overlapping Sociable Tests to allow easily test and evolve individual behaviours (ex : class serialization) while still being able to split/merge/refactor classes inside some class clusters by not checking specific calls between them.
  7. mock_secondary_ports_in_behat branch (see Pull Request): Mock Secondary Ports (according to Hexagonal architecture) in Behat. Makes behat tests much faster and easier to write. Pre-requisite : well defined secondary ports and Integration tests on their Infrastructure layer implementation.

API documentation

Example :

curl -i -X PUT "https://virtserver.swaggerhub.com/JMLamodiere/tdd-demo_forum_php_2020/1.0.0/runningsessions/42" -H  "accept: application/json" -H  "Content-Type: application/json" -d "{\"id\":42,\"distance\":5.5,\"shoes\":\"Adadis Turbo2\"}"

Makefile

Run make or make help to see available commands.

Test environment

Pre-requisites :

Run tests with:

make install
make test

Dev environment

Pre-requisites (see composer.json) :

Create an App on AccuWeather and copy your API Key:

# in /.env.dev.local
ACCUWEATHER_API_KEY=xxx

Start local dev environment with:

composer install
make start

Postgresql

To access Postgresql database, configure a tool such as Database Tools and SQL included in PHPStorm:

  • URL: jdbc:postgresql://localhost:32774/forumphp (replace 32774 with the port given by make ps command)
  • login: forumphp
  • password: forumphp (see docker-compose.yml)

Wiremock

See Swagger UI documentation at http://localhost:32775/__admin/swagger-ui/

Replace 32775 with the port given by make ps command


Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Php (391,849) 
Docker (33,750) 
Docker Compose (6,474) 
Symfony (2,965) 
Tdd (1,533) 
Ddd (1,090) 
Hexagonal Architecture (265) 
Behat (135) 
Related Projects
Advertising 📦 9
All Projects
Application Programming Interfaces 📦 120
Applications 📦 181
Artificial Intelligence 📦 72
Blockchain 📦 70
Build Tools 📦 111
Cloud Computing 📦 79
Code Quality 📦 28
Collaboration 📦 30
Command Line Interface 📦 48
Community 📦 81
Companies 📦 60
Compilers 📦 60
Computer Science 📦 74
Configuration Management 📦 39
Content Management 📦 167
Control Flow 📦 197
Data Formats 📦 77
Data Processing 📦 266
Data Storage 📦 132
Economics 📦 60
Frameworks 📦 198
Games 📦 122
Graphics 📦 103
Hardware 📦 148
Integrated Development Environments 📦 47
Learning Resources 📦 147
Legal 📦 28
Libraries 📦 119
Lists Of Projects 📦 21
Machine Learning 📦 336
Mapping 📦 61
Marketing 📦 15
Mathematics 📦 55
Media 📦 228
Messaging 📦 97
Networking 📦 304
Operating Systems 📦 84
Operations 📦 120
Package Managers 📦 52
Programming Languages 📦 229
Runtime Environments 📦 96
Science 📦 42
Security 📦 375
Social Media 📦 26
Software Architecture 📦 70
Software Development 📦 68
Software Performance 📦 57
Software Quality 📦 127
Text Editors 📦 45
Text Processing 📦 131
User Interface 📦 310
User Interface Components 📦 465
Version Control 📦 29
Virtualization 📦 68
Web Browsers 📦 38
Web Servers 📦 25
Web User Interface 📦 194