Skip to content

Commit 40e8bab

Browse files
committed
bad implementation
1 parent 9692f58 commit 40e8bab

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2835
-273
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ indent_size = 4
1818
[docs/**openapi.yml]
1919
indent_size = 2
2020

21+
[docker-compose*.yml]
22+
indent_size = 2
23+
2124
[*.json]
2225
indent_size = 4
2326

.env

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2).
1414
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration
1515

16+
# See https://home.openweathermap.org/api_keys
17+
# OPENWEATHER_API_KEY=??? (defined in .env.local ignored by .gitignore)
18+
# See https://developer.accuweather.com/user/me/apps
19+
# ACCUWEATHER_API_KEY=??? (defined in .env.local ignored by .gitignore)
20+
ACCUWEATHER_BASE_URI='http://dataservice.accuweather.com/'
21+
1622
###> symfony/framework-bundle ###
1723
APP_ENV=dev
1824
APP_SECRET=d63e877b0444331114e7842dd8105ae1
@@ -25,3 +31,12 @@ CORS_ALLOW_CREDENTIALS=true
2531
CORS_ORIGIN_REGEX=false
2632
CORS_ALLOW_ORIGIN=*
2733
###< nelmio/cors-bundle ###
34+
35+
###> doctrine/doctrine-bundle ###
36+
# Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
37+
# For an SQLite database, use: "sqlite:///%kernel.project_dir%/var/data.db"
38+
# For a PostgreSQL database, use: "postgresql://db_user:[email protected]:5432/db_name?serverVersion=11&charset=utf8"
39+
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
40+
# DATABASE_URL=mysql://db_user:[email protected]:3306/db_name?serverVersion=5.7
41+
# NB : already set in dev and test by symfony server, see https://symfony.com/doc/4.4/setup/symfony_server.html#docker-integration
42+
###< doctrine/doctrine-bundle ###

.env.test

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,11 @@
22
KERNEL_CLASS='App\Kernel'
33
APP_SECRET='$ecretf0rt3st'
44
SYMFONY_DEPRECATIONS_HELPER=999999
5+
6+
ACCUWEATHER_API_KEY='accuweatherTestKey'
7+
ACCUWEATHER_BASE_URI='http://wiremock:8080/'
8+
9+
###> doctrine/doctrine-bundle ###
10+
# See docker-compose.yml
11+
DATABASE_URL=postgres://forumphp:forumphp@database:5432/forumphp?sslmode=disable&charset=utf8
12+
###< doctrine/doctrine-bundle ###

.travis.yml

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
# Ensure that PHP is installed in Travis' build environment. Travis provides several versions of
2-
# PHP like 5.6, 7.0, 7.1, 7.2, 7.3, 7.4, etc., each of them including XDebug and PHPUnit.
3-
language: php
41
sudo: false
52

3+
env:
4+
global:
5+
- APP_ENV = test
6+
7+
services:
8+
- docker
9+
610
# Travis can cache content between builds. This speeds up the build process and saves resources.
711
cache:
8-
yarn: true
912
directories:
1013
# Cache composer packages so "composer install" is faster.
1114
- $HOME/.composer/cache/files
@@ -16,27 +19,16 @@ jobs:
1619
# conditions are met: The only remaining jobs are allowed to fail, or a job has already failed. In
1720
# these cases, the status of the build can already be determined, so there’s no need to wait around
1821
fast_finish: true
19-
include:
20-
- php: 7.4
2122

2223
branches:
2324
only:
2425
- main
2526

2627
before_install:
27-
- phpenv config-rm xdebug.ini || true
28+
- make preinstall
2829

2930
install:
30-
- composer install
31+
- make install
3132

3233
script:
33-
- ./vendor/bin/phpunit
34-
- ./vendor/bin/behat
35-
# this checks that the source code follows the Symfony Code Syntax rules
36-
- './vendor/bin/php-cs-fixer --config=.php_cs.dist fix --diff --dry-run -v'
37-
# this checks that the YAML config files contain no syntax errors
38-
- ./bin/console lint:yaml config --parse-tags
39-
# This checks that arguments injected into services match type declarations.
40-
- ./bin/console lint:container
41-
# this checks that the composer.json and composer.lock files are valid
42-
- composer validate --strict
34+
- make test

Makefile

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,55 @@ SHELL := $(shell which bash)
1414
help: ## Show Help
1515
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
1616

17-
serve: ## Run local dev server
17+
# Dev environment. Require php and symfony executables
18+
19+
start: ## [dev] Start local dev server
20+
docker-compose up -d
1821
symfony serve -d
1922

20-
log: ## Follow logs on local dev server
23+
ps: ## [dev] docker-compose ps
24+
docker-compose ps
25+
26+
server-logs: ## [dev] Follow logs on local dev server
2127
symfony server:log
2228

23-
stop: ## Stop local dev server
29+
docker-logs: ## [dev] Follow logs on docker containers
30+
docker-compose logs -f
31+
32+
stop: ## [dev] Stop local dev server
2433
symfony server:stop
34+
docker-compose stop
35+
36+
prune: ## [dev] Prune docker containers
37+
docker-compose down -v --rmi local --remove-orphans
38+
39+
fix-style: ## [dev] Run php-cs-fixer
40+
vendor/bin/php-cs-fixer fix --config=.php_cs.dist -v
2541

26-
test:phpunit ## Run all tests
42+
# Test / CI environment. Require docker and docker-compose executables
43+
44+
preinstall: ## Pre-install steps
45+
docker-compose up -d
46+
47+
install: ## Install steps
48+
docker-compose run php composer install
49+
50+
test:lint ## Run all tests
51+
test:phpunit
2752
test:behat
2853

54+
lint: ## Run all linters
55+
# Checks coding standards. Fixable with "make fix-style"
56+
docker-compose run php ./vendor/bin/php-cs-fixer --config=.php_cs.dist fix --diff --dry-run -v
57+
# checks that the YAML config files contain no syntax errors
58+
docker-compose run php ./bin/console lint:yaml config --parse-tags
59+
# checks that arguments injected into services match type declarations.
60+
docker-compose run php ./bin/console lint:container
61+
# checks that the composer.json and composer.lock files are valid
62+
docker-compose run php composer validate --strict
63+
2964
phpunit: ## Run phpunit
30-
vendor/bin/phpunit
65+
docker-compose run php vendor/bin/phpunit
3166

3267
behat: ## Run behat
33-
vendor/bin/behat
34-
35-
fix-style: ## Run php-cs-fixer
36-
vendor/bin/php-cs-fixer fix --config=.php_cs.dist -v
68+
docker-compose run php vendor/bin/behat

README.md

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,74 @@
11
# TDD Demo - ForumPHP 2020
22

3+
[![Build Status](https://travis-ci.com/JMLamodiere/tdd-demo-forumphp2020.svg?branch=main)](https://travis-ci.com/JMLamodiere/tdd-demo-forumphp2020)
4+
35
Forum PHP 2020 talk (in French) : [Trop de mock tue le test : ce que l'archi hexagonale a changé](https://event.afup.org/forum-php-2020/programme-forum-php-2020/#3414)
46

7+
:warning: **WARNING:** The [bad_implementation](https://github.com/JMLamodiere/tdd-demo-forumphp2020/tree/bad_implementation)
8+
branch contains example of bad practices ! See [main](https://github.com/JMLamodiere/tdd-demo-forumphp2020) branch
9+
for correct implementation.
10+
511
## API documentation
612

713
- Local : [docs/openapi.yml](docs/openapi.yml)
814
- Github Pages : https://jmlamodiere.github.io/tdd-demo-forumphp2020
9-
- Swaggger Hub : https://app.swaggerhub.com/apis/JMLamodiere/tdd-demo_forum_php_2020/1.0.0
15+
- Swaggger Hub (with online mock) : https://app.swaggerhub.com/apis/JMLamodiere/tdd-demo_forum_php_2020/1.0.0
1016

1117
## Makefile
1218

1319
Run `make` or `make help` to see available commands.
20+
21+
### Test environment
22+
23+
Pre-requisites :
24+
25+
- [docker](https://www.docker.com/)
26+
- [docker-compose](https://docs.docker.com/compose/)
27+
28+
Run tests with:
29+
30+
make install
31+
make test
32+
33+
### Dev environment
34+
35+
Pre-requisites (see [composer.json](composer.json)) :
36+
37+
- PHP >= 7.4
38+
- ext-pgsql
39+
- [Symfony local web server](https://symfony.com/doc/current/setup/symfony_server.html)
40+
41+
Start local dev environment with:
42+
43+
```
44+
composer install
45+
make start
46+
```
47+
48+
- Symfony homepage (404): https://127.0.0.1:8000/
49+
- Symfony profiler: https://127.0.0.1:8000/_profiler/
50+
51+
### SwaggerHub mock server
52+
53+
An online mock server is auto-generated based on openapi doc at https://virtserver.swaggerhub.com/JMLamodiere/tdd-demo_forum_php_2020/1.0.0 . Example :
54+
55+
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\"}"
56+
57+
## Postgresql
58+
59+
To access Postgresql database, configure a tool such as
60+
[Database Tools and SQL](https://www.jetbrains.com/help/phpstorm/connecting-to-a-database.html#connect-to-postgresql-database)
61+
included in PHPStorm:
62+
63+
- URL: `jdbc:postgresql://localhost:32774/forumphp` (replace `32774` with the port given by `make ps` command)
64+
- login: `forumphp`
65+
- password: `forumphp` (see [docker-compose.yml](docker-compose.yml))
66+
67+
## Wiremock
68+
69+
- Local server: https://hub.docker.com/r/rodolpheche/wiremock/ (see [docker-compose.yml](docker-compose.yml))
70+
- PHP Client: https://github.com/rowanhill/wiremock-php (used in PHP tests)
71+
72+
See Swagger UI documentation at http://localhost:32775/__admin/swagger-ui/
73+
74+
Replace `32775` with the port given by `make ps` command

behat.yml.dist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ default:
44
contexts:
55
- FeatureContext:
66
kernel: '@kernel'
7+
dbal: '@doctrine.dbal.default_connection'
8+
accuweatherApiKey: '%%accuweather.apikey%%'
79

810
extensions:
911
Behat\Symfony2Extension:

composer.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,27 @@
88
"ext-ctype": "*",
99
"ext-iconv": "*",
1010
"ext-json": "*",
11+
"ext-pgsql": "*",
12+
"doctrine/doctrine-bundle": "^2.1",
13+
"guzzlehttp/guzzle": "^7.2",
1114
"symfony/console": "4.4.*",
1215
"symfony/dotenv": "4.4.*",
1316
"symfony/flex": "^1.3.1",
1417
"symfony/framework-bundle": "4.4.*",
15-
"symfony/yaml": "4.4.*"
18+
"symfony/serializer": "4.4.*",
19+
"symfony/yaml": "4.4.*",
20+
"webmozart/assert": "^1.9"
1621
},
1722
"require-dev": {
1823
"behat/behat": "^3.7",
1924
"behat/symfony2-extension": "^2.1",
2025
"friendsofphp/php-cs-fixer": "^2.16",
2126
"nelmio/cors-bundle": "^2.1",
27+
"phpspec/prophecy-phpunit": "^2.0",
2228
"phpunit/phpunit": "^9.4",
2329
"symfony/phpunit-bridge": "^5.1",
24-
"symfony/web-profiler-bundle": "4.4.*"
30+
"symfony/web-profiler-bundle": "4.4.*",
31+
"wiremock-php/wiremock-php": "^2.27"
2532
},
2633
"config": {
2734
"platform": {
@@ -39,7 +46,7 @@
3946
},
4047
"autoload-dev": {
4148
"psr-4": {
42-
"App\\Tests\\": "tests/"
49+
"App\\": "tests/"
4350
}
4451
},
4552
"replace": {

0 commit comments

Comments
 (0)