diff --git a/.gitignore b/.gitignore index e7195725..69a46860 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,8 @@ /public/build/fonts/glyphicons-* /public/build/images/glyphicons-* +Makefile.custom + ###> symfony/framework-bundle ### .env /public/bundles/ diff --git a/Makefile b/Makefile new file mode 100755 index 00000000..1723e6b0 --- /dev/null +++ b/Makefile @@ -0,0 +1,78 @@ +# Makefile +# +# This file contains the commands most used in DEV, plus the ones used in CI and PRD environments. +# +# The commands are to be organized semantically and alphabetically, so that similar commands are nex to each other +# and we can compare them and update them easily. +# +# For example in a format like `subject-action-environment`, ie: +# +# cs-fix: # here we don't use the env because we only do it in dev +# dep-install: # again, by default the env is dev +# dep-install-prd: +# dep-update: +# test: # here we don't even have a subject because it is the app itself, and by default the env is dev +# + +# Mute all `make` specific output. Comment this out to get some debug information. +.SILENT: + +# .DEFAULT: If the command does not exist in this makefile +# default: If no command was specified +.DEFAULT default: + if [ -f ./Makefile.custom ]; then \ + $(MAKE) -f Makefile.custom "$@"; \ + else \ + if [ "$@" != "" ]; then echo "Command '$@' not found."; fi; \ + $(MAKE) help; \ + if [ "$@" != "" ]; then exit 2; fi; \ + fi + +help: + @echo "Usage:" + @echo " make [command]" + @echo + @echo "Available commands:" + @grep '^[^#[:space:]].*:' Makefile | grep -v '^default' | grep -v '^\.' | grep -v '=' | grep -v '^_' | sed 's/://' | xargs -n 1 echo ' -' + +######################################################################################################################## + +COVERAGE_REPORT_PATH="var/coverage.clover.xml" +DB_PATH='var/data/blog.sqlite' + +# We run this in tst ENV so that we never run it with xdebug on +cs-fix: + php vendor/bin/php-cs-fixer fix --verbose + +db-setup: + mkdir -p var/data + php bin/console doctrine:database:drop -n --force + php bin/console doctrine:database:create -n + php bin/console doctrine:schema:create -n + php bin/console doctrine:fixtures:load -n + +dep-clearcache: + composer clearcache + +dep-install: + composer install + +dep-install-prd: + composer install --no-dev --optimize-autoloader --no-ansi --no-interaction --no-progress --no-scripts + +dep-update: + composer update + +test: + $(MAKE) db-setup + php vendor/bin/phpunit + $(MAKE) cs-fix + +# We use phpdbg because is part of the core and so that we don't need to install xdebug just to get the coverage. +# Furthermore, phpdbg gives us more info in certain conditions, ie if the memory_limit has been reached. +test_cov: + phpdbg -qrr vendor/bin/phpunit --coverage-text --coverage-clover=${COVERAGE_REPORT_PATH} + +up: + if [ ! -f ${DB_PATH} ]; then $(MAKE) db-setup; fi + php bin/console server:run 0.0.0.0:8000 diff --git a/Makefile.custom.dist b/Makefile.custom.dist new file mode 100755 index 00000000..a8902ac9 --- /dev/null +++ b/Makefile.custom.dist @@ -0,0 +1,29 @@ +# Makefile.custom +# +# This file contains the custom commands and/or aliases. +# +# To use it, copy/paste this file with the name Makefile.custom and add commands as you wish. +# This file is in .gitignore, so it will not be committed and is specific to you. +# + +# Mute all `make` specific output. Comment this out to get some debug information. +.SILENT: + +# make commands be run with `bash` instead of the default `sh` +SHELL='/bin/bash' + +# .DEFAULT: If command does not exist in this makefile +# default: If no command was specified: +.DEFAULT default: + if [ "$@" != "" ]; then echo "Command '$@' not found."; fi; + $(MAKE) help # goes to the main Makefile + $(MAKE) -f Makefile.custom help # goes to this Makefile + if [ "$@" != "" ]; then exit 2; fi; + +help: + @echo + @echo "Available custom commands:" + @grep '^[^#[:space:]].*:' Makefile.custom | grep -v '^help' | grep -v '^default' | grep -v '^\.' | grep -v '=' | grep -v '^_' | sed 's/://' | xargs -n 1 echo ' -' + +######################################################################################################################## + diff --git a/README.md b/README.md index aa3e03b2..9382725c 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,14 @@ browser at : ```bash $ cd symfony-demo/ -$ php bin/console server:run +$ make up +``` + +To see all commands available run: + +```bash +$ cd symfony-demo/ +$ make ``` Alternatively, you can [configure a fully-featured web server][2] like Nginx @@ -44,7 +51,14 @@ Execute this command to run tests: ```bash $ cd symfony-demo/ -$ ./vendor/bin/phpunit +$ make test +``` + +Or this command to run tests and get the coverage: + +```bash +$ cd symfony-demo/ +$ make test_cov ``` [1]: https://symfony.com/doc/current/reference/requirements.html