{"id":13616897,"url":"https://github.com/JMLamodiere/tdd-demo-forumphp2020","last_synced_at":"2025-04-14T03:31:55.102Z","repository":{"id":37518829,"uuid":"304663896","full_name":"JMLamodiere/tdd-demo-forumphp2020","owner":"JMLamodiere","description":"Live coding examples used during Forum PHP 2020 talk \"Too many mocks killed the test: What Hexagonal Architecture has changed\"","archived":false,"fork":false,"pushed_at":"2023-02-02T09:53:05.000Z","size":310,"stargazers_count":34,"open_issues_count":8,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-11-08T01:37:30.458Z","etag":null,"topics":["behat","ddd","docker","docker-compose","hexagonal-architecture","php","prophecy","symfony","tdd","wiremock"],"latest_commit_sha":null,"homepage":"https://speakerdeck.com/jmlamodiere/too-many-mocks-killed-the-test-what-hexagonal-architecture-has-changed","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JMLamodiere.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-10-16T15:16:58.000Z","updated_at":"2024-06-28T05:49:17.000Z","dependencies_parsed_at":"2023-02-17T18:01:24.202Z","dependency_job_id":null,"html_url":"https://github.com/JMLamodiere/tdd-demo-forumphp2020","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JMLamodiere%2Ftdd-demo-forumphp2020","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JMLamodiere%2Ftdd-demo-forumphp2020/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JMLamodiere%2Ftdd-demo-forumphp2020/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JMLamodiere%2Ftdd-demo-forumphp2020/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JMLamodiere","download_url":"https://codeload.github.com/JMLamodiere/tdd-demo-forumphp2020/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248815595,"owners_count":21165952,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["behat","ddd","docker","docker-compose","hexagonal-architecture","php","prophecy","symfony","tdd","wiremock"],"created_at":"2024-08-01T20:01:34.538Z","updated_at":"2025-04-14T03:31:50.086Z","avatar_url":"https://github.com/JMLamodiere.png","language":"PHP","funding_links":[],"categories":["PHP"],"sub_categories":[],"readme":"# TDD Demo - ForumPHP 2020\n\n[![Build Status](https://travis-ci.com/JMLamodiere/tdd-demo-forumphp2020.svg?branch=main)](https://travis-ci.com/JMLamodiere/tdd-demo-forumphp2020)\n\nLive coding examples used during [Forum PHP 2020 talk](https://afup.org/talks/3414-trop-de-mock-tue-le-test-ce-que-l-archi-hexagonale-a-change):\n\n- [:fr: :arrow_forward: Voir sur Youtube](http://www.youtube.com/watch?v=rSO1y3lCBfk)\n- [:fr: :clipboard: Trop de mock tue le test : ce que l'archi hexagonale a changé](https://speakerdeck.com/jmlamodiere/trop-de-mock-tue-le-test-ce-que-larchi-hexagonale-a-change)\n- [:uk: :clipboard: Too many mocks killed the test: What Hexagonal Architecture has changed](https://speakerdeck.com/jmlamodiere/too-many-mocks-killed-the-test-what-hexagonal-architecture-has-changed)\n\nFor a bit of theory, see [:fr: De CRUD à DDD, comment Meetic a sauvé son legacy](https://afup.org/talks/3037-de-crud-a-ddd-comment-meetic-a-sauve-son-legacy)\n\n## Steps by step refactoring\n\n:warning: **Warning** : Only steps 1 \u0026 2 are really considered *bad*. Next steps just show different testing styles.\n\n1. [bad_implementation](https://github.com/JMLamodiere/tdd-demo-forumphp2020/tree/bad_implementation) branch\ncontains :\n    - Architecture mistakes according to [Hexagonal architecture](https://alistair.cockburn.us/hexagonal-architecture/) (aka Port \u0026 Adapters)\n    - Tests too much coupled with implementation details, and an incorrect usage of mocks\n1. [bad_tests](https://github.com/JMLamodiere/tdd-demo-forumphp2020/tree/bad_tests) branch\n[(see Pull Request)](https://github.com/JMLamodiere/tdd-demo-forumphp2020/pull/12) only fixes (some) hexagonal mistakes.\nMany obscure changes are required in the tests, proving they do not help much during refactoring\n1. [integration_infra_medium_domain](https://github.com/JMLamodiere/tdd-demo-forumphp2020/tree/integration_infra_medium_domain) branch\n[(see Pull Request)](https://github.com/JMLamodiere/tdd-demo-forumphp2020/pull/13) split tests this way:\n    - Domain logic (Application/Domain folders): medium Unit tests, mocking only infrastructure\n    - Technical logic (Infrastructure folder): integration tests for each specific technology\n1. [integration_infra_medium_domain_wiremock](https://github.com/JMLamodiere/tdd-demo-forumphp2020/tree/integration_infra_medium_domain_wiremock) branch\n[(see Pull Request)](https://github.com/JMLamodiere/tdd-demo-forumphp2020/pull/14)\nonly replaces [Guzzle MockHandler](https://docs.guzzlephp.org/en/stable/testing.html) with [Wiremock](#wiremock),\ndecoupling HTTP tests with the library being used for HTTP calls.\n1. [integration_infra_medium_domain_no_di](https://github.com/JMLamodiere/tdd-demo-forumphp2020/tree/integration_infra_medium_domain_no_di) branch\n   [(see Pull Request)](https://github.com/JMLamodiere/tdd-demo-forumphp2020/pull/15)\n   removes [Dependency Injection Container](https://www.loosecouplings.com/2011/01/dependency-injection-using-di-container.html)\n   usage and manually build tested classes instead.\n1. [integration_infra_sociable](https://github.com/JMLamodiere/tdd-demo-forumphp2020/tree/integration_infra_sociable) branch\n   [(see Pull Request)](https://github.com/JMLamodiere/tdd-demo-forumphp2020/pull/16)\n   replaces medium sized tests with [Overlapping Sociable Tests](https://www.jamesshore.com/v2/blog/2018/testing-without-mocks#sociable-tests)\n   to allow easily test and evolve individual behaviours (ex : class serialization) while still being able to\n   split/merge/refactor classes inside some class clusters by not checking specific calls between them.\n1. [mock_secondary_ports_in_behat](https://github.com/JMLamodiere/tdd-demo-forumphp2020/tree/mock_secondary_ports_in_behat) branch\n   [(see Pull Request)](https://github.com/JMLamodiere/tdd-demo-forumphp2020/pull/18): Mock Secondary Ports\n   (according to [Hexagonal architecture](https://alistair.cockburn.us/hexagonal-architecture/)) in\n   [Behat](https://behat.org). Makes behat tests much faster and\n   easier to write. Pre-requisite : well defined secondary ports and Integration tests on their\n   Infrastructure layer implementation.\n\n## API documentation\n\n- Local : [docs/openapi.yml](docs/openapi.yml)\n- Github Pages : https://jmlamodiere.github.io/tdd-demo-forumphp2020\n- Swaggger Hub (with [SwaggerHub API Auto Mocking](https://app.swaggerhub.com/help/integrations/api-auto-mocking)\nactivated) : https://app.swaggerhub.com/apis/JMLamodiere/tdd-demo_forum_php_2020/1.0.0\n\nExample :\n\n    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\\\"}\"\n\n## Makefile\n\nRun `make` or `make help` to see available commands.\n\n### Test environment\n\nPre-requisites :\n\n- [docker](https://www.docker.com/)\n- [docker-compose](https://docs.docker.com/compose/)\n\nRun tests with:\n\n    make install\n    make test\n\n### Dev environment\n\nPre-requisites (see [composer.json](composer.json)) :\n\n- PHP \u003e= 7.4\n- ext-pgsql\n- [Symfony local web server](https://symfony.com/doc/current/setup/symfony_server.html)\n\nCreate an App on [AccuWeather](https://developer.accuweather.com/) and copy your API Key:\n\n```\n# in /.env.dev.local\nACCUWEATHER_API_KEY=xxx\n```\n\nStart local dev environment with:\n\n```\ncomposer install\nmake start\n```\n\n- Symfony homepage (404): https://127.0.0.1:8000/\n- Symfony profiler: https://127.0.0.1:8000/_profiler/\n\n## Postgresql\n\nTo access Postgresql database, configure a tool such as\n[Database Tools and SQL](https://www.jetbrains.com/help/phpstorm/connecting-to-a-database.html#connect-to-postgresql-database)\nincluded in PHPStorm:\n\n- URL: `jdbc:postgresql://localhost:32774/forumphp` (replace `32774` with the port given by `make ps` command)\n- login: `forumphp`\n- password: `forumphp` (see [docker-compose.yml](docker-compose.yml))\n\n## Wiremock\n\n- Local server: https://hub.docker.com/r/rodolpheche/wiremock/ (see [docker-compose.yml](docker-compose.yml))\n- PHP Client: https://github.com/rowanhill/wiremock-php (used in PHP tests)\n\nSee Swagger UI documentation at http://localhost:32775/__admin/swagger-ui/\n\nReplace `32775` with the port given by `make ps` command\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJMLamodiere%2Ftdd-demo-forumphp2020","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FJMLamodiere%2Ftdd-demo-forumphp2020","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJMLamodiere%2Ftdd-demo-forumphp2020/lists"}