Skip to content

Example Symfony CRUD DDD hexagonal architecture app

Notifications You must be signed in to change notification settings

ttibensky/symfony-ddd-hex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Example Symfony CRUD DDD hexagonal architecture app

Local usage

The Symfony web app runs on http://localhost:8080.

Requirements

  • Linux, preferably Ubuntu or Debian
    • other linus distros and operating systems (such as Windows od Mac OS) are not tested
    • php docker image might not run as expected on ARM CPUs (such as new Macbooks and Macs), the images are not tested on ARM
  • Docker & docker compose

First startup

Copy docker-compose.override.example.yml into docker-compose.override.yml.

# start containers and watch the logs until:
# - mysql container imports the database dump and you will see "ready for connections" in the mysql container logs
# - php container installs composer dependencies, successfully connects to mysql container and executes database migrations
# - once the above is done, you will see "fpm is running" and "ready to handle connections" in the php container logs
#
# if something does not seem right with the first startup, please see container logs and/or contact maintainer of this repository
docker compose up

Normal usage

# to start container
docker compose up -d

# install composer dependencies
docker compose exec symfony bash -c 'XDEBUG_MODE=off composer install --prefer-dist --optimize-autoloader'

# make & execute pending database migrations
docker compose exec symfony bin/console make:migration
docker compose exec symfony bin/console doctrine:migrations:migrate --no-interaction --all-or-nothing
# rollback last transaction
docker compose exec symfony bin/console doctrine:migrations:migrate --no-interaction prev

# connect to mysql
docker compose exec mysql mysql -usymfony -pzTL32UkUGpoX --default-character-set=utf8mb4 symfony
# create sql dump
docker compose exec mysql mysqldump -uroot -pzTL32UkUGpoX --default-character-set=utf8mb4 symfony > ./mysql/init/1_symfony.sql

# reset database
docker compose exec symfony bin/console doctrine:database:drop --force
docker compose exec symfony bin/console doctrine:database:create
docker compose exec symfony bin/console doctrine:migrations:migrate --no-interaction --all-or-nothing
# the fixtures might take a while to finish
docker compose exec symfony bin/console doctrine:fixtures:load --no-interaction

Tests

Reset database, SQL connection & dump

Before the first test run (functional or acceptance), you need to run migrations and fixtures on the test database using the commands below. Reset database is also needed from time to time when you test database gets outdated (or if you encounter seamingly random errors).

# reset database
docker compose exec symfony bin/console doctrine:database:drop --force --env=test
docker compose exec symfony bin/console doctrine:database:create --env=test
docker compose exec symfony bin/console doctrine:migrations:migrate --no-interaction --env=test --all-or-nothing
# the fixtures might take a while to finish
docker compose exec symfony bin/console doctrine:fixtures:load --no-interaction --env=test

# connect to mysql
docker compose exec mysql mysql -usymfony -pzTL32UkUGpoX --default-character-set=utf8mb4 symfony_test
# create sql dump
docker compose exec mysql mysqldump -uroot -pzTL32UkUGpoX --default-character-set=utf8mb4 symfony_test > ./mysql/init/3_symfony_test.sql

Unit tests

clear && docker compose exec symfony php vendor/bin/codecept run unit

Functional tests

clear && docker compose exec symfony php vendor/bin/codecept run functional

Acceptance tests

If you would like to run acceptance test, uncomment firefox container in your docker-compose.override.yml. To run acceptance tests, you need to have firefox instance running. It can be resource heavy, so it is commented out by default.

clear && docker compose exec symfony php vendor/bin/codecept run acceptance

Sources of inspiration

TODO

  • resolve TODOs in the code
  • translations
  • add architecture diagram
  • add code dependency graph visualisation to point out potential problems
  • add static code analysis, linter
  • check if there are strict_types everywhere and if we still need to declare it everywhere
  • handle exceptions in controllers
  • add test coverage report, maybe also a badge to this readme
  • pre-commit hooks to run tests

About

Example Symfony CRUD DDD hexagonal architecture app

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published