Skip to content

cyrilverloop/symfony-demo

Repository files navigation

symfony-demo

This is a simple Symfony 8.0 demo project using PHP 8.5.

This demo is using AssetMapper. To see a version with Encore, switch to the unmaintained webpack-encore branch.

License Type coverage Minimum PHP version

Installation

Downloading the project :

user@host ~$ cd [PATH_WHERE_TO_PUT_THE_PROJECT] # E.g. ~/projects/
user@host projects$ git clone https://github.com/cyrilverloop/symfony-demo.git
user@host projects$ cd symfony-demo

This demo uses Docker images based on :

  1. mariadb for the database;
  2. httpd:alpine for the web server;
  3. php:8.5.0-fpm-alpine for php files;
  4. alpine/openssl to generate a TLS certificate.

The app (php) container depends on the mariadb and httpd containers. After each docker compose run --rm php ... command, Docker will not remove the dependencies (mariadb, httpd and network). You can remove them with :

user@host symfony-demo$ docker compose down

Create the cache directories (recommended)

It is recommended to use cache directories for the downloaded dependencies (Composer and Phive). If you do not already have cache directories, create them with :

user@host symfony-demo$ mkdir -p ./.cache/composer/ ./.cache/phive/

Default paths are configured in compose.override.yaml.dist and you can customise them in compose.override.yaml.

Generate a certificate

Generate a TLS self-signed certificate with the following script :

user@host symfony-demo$ ./tls/create-self-signed-certificate.sh

Building the images

Copy the example files :

user@host symfony-demo$ cp compose.override.yaml.dist compose.override.yaml
user@host symfony-demo$ cp ./.env.dist ./.env
user@host symfony-demo$ cp httpd/.ashrc.dist httpd/.ashrc
user@host symfony-demo$ cp php/.ashrc.dist php/.ashrc

Fill in the variables in ./.env. These files are in the .gitignore file and can be customised.

Build the images :

user@host symfony-demo$ docker compose build

Installing PHP dependencies

Define the database configuration for Symfony (see ./app/.env or ./app/.env.local.dist) and install the PHP dependencies :

user@host symfony-demo$ docker compose run --rm php composer install -o [--no-dev]

The "--no-dev" option is for the production environment.

For the development and the test environments only :

user@host symfony-demo$ docker compose run --rm php phive install --trust-gpg-keys 4AA394086372C20A,12CE0F1D262429A5,31C7E470E2138192,8AC0BAA79732DD42,C5095986493B4AA0

Creating the database

user@host symfony-demo$ docker compose run --rm php ./bin/console doctrine:database:create [-e test]
user@host symfony-demo$ docker compose run --rm php ./bin/console doctrine:migrations:migrate [--no-interaction] [-e test]

The "-e test" option is to for the test environment which uses Sqlite.

Serving assets in production

user@host symfony-demo$ docker compose run --rm php bin/console asset-map:compile

Usage

Once the installation is complete, you can start the containers with :

user@host symfony-demo$ docker compose up -d

The demo will be available in your browser through : https://localhost:8000/

To stop the containers :

user@host symfony-demo$ docker compose down

Tests

First, you need to configure the app and create the database for the test environment. Then, run the tests :

user@host symfony-demo$ docker compose run --rm php ./tools/phpunit -c ./ci/phpunit.xml

The generated outputs will be in ./app/ci/phpunit/.

And, run the mutation tests :

user@host symfony-demo$ docker compose run --rm php ./tools/infection -c./ci/infection.json

The generated outputs will be in ./app/ci/infection/.

PHPDoc

To generate the PHPDoc, use this command after installing phive dependencies :

user@host symfony-demo$ docker compose run --rm php ./tools/phpDocumentor --config ./ci/phpdoc.xml

The generated HTML documentation will be in ./app/ci/phpdoc/.

About

This is a simple Symfony 8.0 demo project using PHP 8.5.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages