Project 8 - Update and improve an existing project
Mandatory :
PHP >= 8.0
Symfony CLI
Optional :
Make
to use the Makefile and custom commandsDocker
andDocker-compose
for MySQL database and PhpMyAdmin containers
Unit Tests :
PHPUnit
-
To get this project on your local machine, simply clone this repository :
git clone [email protected]:OlivierFL/Floch_Olivier_8_19062021.git
-
Install the dependencies :
composer install
-
Environment configuration :
To configure local dev environment, create a
.env.local
file at the root of the project.To configure database connection, override the
DATABASE_URL
env variable with your database credentials and database name, for example :DATABASE_URL="mysql://root:[email protected]:3306/todo?serverVersion=5.7"
If you're using the MySQL Docker container, the config is :
DATABASE_URL="mysql://root:[email protected]:3306/todo"
-
After configuring the database connection, run
bin/console doctrine:database:create
to create the database, thenbin/console doctrine:schema:create
to create database tables. -
Then run
bin/console doctrine:fixtures:load
to load the example data into the database. If you're using Docker, PhpMyAdmin is available onlocalhost:8080
(user :root
, password :admin
). -
By default
7.Start the Symfony server with symfony server:start -d
.
The base url for the API is : localhost:8000
.
List of useful commands to use the project :
symfony server:start
to start the Symfony serversymfony server:stop
to stop the Symfony server
Commands to use with Docker and Make (commands are available in Makefile at the root of the project) :
make up
to start Docker stack (MySQL and PhpMyAdmin) and Symfony servermake install
to run installation process automatically (manual environment configuration is needed before running this command)make tests
to run all PHPUnit tests, the database is reset before running the tests (see tests) to know how to configure the environment to run the testsmake tests-coverage
to run all PHPUnit tests with code coveragemake tests-functional
to run only functional PHPUnit testsmake tests-entity
to run only PHPUnit unit tests for entitiesmake tests-no-reset
to run all PHPUnit tests, without resetting the databasemake down
to stop Docker stack (MySQL and PhpMyAdmin) and Symfony server
In order to have a fully functional application, the fixtures contains :
-
2 Users with different roles :
-
an Admin user (with
ROLE_ADMIN
role) with [email protected] email, and admin1234 password. -
a simple User (with
ROLE_USER
role) with [email protected] email, and user1234 password.
-
-
A default list of Tasks (36 items).
-
10 Tasks without an author. By default, and to show how this issue is fixed by this pull request, 10 Tasks do not have a User. To fix this, use the Console Command :
bin/console task:set-user
. This command creates an Anonymous User if it does not exist in database, and links this user to the Tasks without an author. -
A default list of Users (26 items). If the above Console Command has been run, an Anonymous User has been added in the database (27 items).
Third party libraries used in this project :
- Faker PHP to generate fake data for fixtures
- Psalm static code analysis
- PHPStan static code analysis
- Easy Coding Standards to check and fix code syntax, bugs, etc.
This project uses Docker for MySQL database and PhpMyAdmin.
The stack is composed of 2 containers :
- mysql
- phpMyAdmin
The configuration is available in the docker-compose.yaml.
PhpUnit is used to run the tests.
Before running the tests, and to have a separate database for tests, create a .env.test.local
file at the root of the project.
In this file, add a DATABASE_URL
env variable to change the database name, for example :
DATABASE_URL="mysql://root:[email protected]:3306/todo_tests"
Then, run these commands in a terminal to create the database used for the tests, and load the fixtures in the test's database :
APP_ENV=test symfony console doctrine:database:create
APP_ENV=test symfony console doctrine:schema:create
APP_ENV=test symfony console doctrine:fixtures:load -n
When using the make tests
command from the Makefile, these commands will be run automatically.
Finally, in a terminal, at the root of the project, run APP_ENV=test symfony php bin/phpunit --colors
or make tests
.
It's possible to generate code coverage report by running APP_ENV=test symfony php bin/phpunit --colors --coverage-html tests-coverage
or make tests-coverage
. The tests-coverage
directory will be created, and the report will be available in a browser by opening the index.html
file from this directory.
Links to code quality tools used for this project:
Codeclimate : https://codeclimate.com/github/OlivierFL/Floch_Olivier_8_19062021
SonarCloud : https://sonarcloud.io/dashboard?id=OlivierFL_Floch_Olivier_8_19062021