Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# In all environments, the following files are loaded if they exist,
# the latter taking precedence over the former:
#
# * .env contains default values for the environment variables needed by the app
# * .env.local uncommitted file with local overrides
# * .env.$APP_ENV committed environment-specific defaults
# * .env.$APP_ENV.local uncommitted environment-specific overrides
#
# Real environment variables win over .env files.
#
# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES.
# https://symfony.com/doc/current/configuration/secrets.html
#
# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2).
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration

###> symfony/framework-bundle ###
APP_ENV=dev
APP_SECRET=b9fabc4b571b22156a8da8caea68f6c0

Check failure on line 19 in .env

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

.env#L19

Generic Secret detected
###< symfony/framework-bundle ###

###> doctrine/doctrine-bundle ###
# Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
#
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data_%kernel.environment%.db"
# DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=8&charset=utf8mb4"
DATABASE_URL="postgresql://app:!ChangeMe!@127.0.0.1:5432/app?serverVersion=16&charset=utf8"
###< doctrine/doctrine-bundle ###

###> symfony/mailer ###
MAILER_DSN=null://null
###< symfony/mailer ###
9 changes: 9 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# define your env variables for the test env here
KERNEL_CLASS='App\Kernel'
APP_SECRET='$ecretf0rt3st'
SYMFONY_DEPRECATIONS_HELPER=999999
PANTHER_APP_ENV=panther
PANTHER_ERROR_SCREENSHOT_DIR=./var/error-screenshots

DATABASE_URL="sqlite:///%kernel.project_dir%/var/test.db"
APP_ENV=test
35 changes: 16 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Symfony 3.4 CI Pipeline
name: Symfony 5.4 CI Pipeline

# Trigger the workflow on push or pull requests for the develop, main, and master branches
on:
Expand All @@ -9,7 +9,7 @@ on:

jobs:
tests:
name: PHPUnit Tests (PHP 7.4)
name: PHPUnit Tests (PHP 8.1)
runs-on: ubuntu-latest

# Provision a containerized MySQL service for integration testing
Expand All @@ -32,13 +32,13 @@ jobs:
- name: Checkout Code
uses: actions/checkout@v4

# 2. Setup PHP Environment with required extensions and tools for Symfony 3.4
# 2. Setup PHP Environment with required extensions and tools for Symfony 5.4
- name: Setup PHP Environment
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
extensions: mbstring, xml, ctype, iconv, pdo, pdo_mysql, mysqli
tools: composer:2.2
php-version: '8.1'
extensions: mbstring, xml, ctype, iconv, intl, pdo, pdo_mysql, mysqli
tools: composer:v2
coverage: none # Disabled to optimize execution speed

# 3. Validate composer.json syntax and integrity
Expand All @@ -47,27 +47,24 @@ jobs:

# 4. Install Project Dependencies using Composer
- name: Install Dependencies
run: composer install --prefer-dist --no-progress --no-suggest
run: composer install --prefer-dist --no-progress

# 5. Inject Symfony 3.4 parameters into GitHub Environment to override local settings
# 5. Inject Symfony 5.4 environment variables into GitHub Environment
- name: Configure Test Environment Variables
run: |
echo "DATABASE_URL=mysql://root:@127.0.0.1:3306/todoco_db" >> $GITHUB_ENV
echo "SYMFONY__DATABASE_HOST=127.0.0.1" >> $GITHUB_ENV
echo "SYMFONY__DATABASE_PORT=3306" >> $GITHUB_ENV
echo "SYMFONY__DATABASE_NAME=todoco_db" >> $GITHUB_ENV
echo "SYMFONY__DATABASE_USER=root" >> $GITHUB_ENV
echo "SYMFONY__DATABASE_PASSWORD=" >> $GITHUB_ENV
echo "DATABASE_URL=mysql://root:@127.0.0.1:3306/todoco_db?serverVersion=5.7" >> $GITHUB_ENV
echo "APP_ENV=test" >> $GITHUB_ENV

# 6. Build the database schema using Doctrine console commands
- name: Initialize Database and Schema
- name: Create Test Database and Load Fixtures
run: |
php bin/console doctrine:database:create --env=test --if-not-exists
php bin/console doctrine:schema:update --env=test --force
php bin/console doctrine:database:create --env=test --if-not-exists
php bin/console doctrine:schema:update --env=test --force
php bin/console doctrine:fixtures:load --env=test --append -n

# 7. Hydrate the isolated database with fixtures
# 7. Hydrate the isolated database with fixtures (forced purge & load)
- name: Load Test Fixtures
run: php bin/console doctrine:fixtures:load --env=test -n
run: php bin/console doctrine:fixtures:load --env=test --purge-with-truncate

# 8. Execute the automated test suite
- name: Run Automated Test Suite
Expand Down
26 changes: 25 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,28 @@
/vendor/
/web/bundles/
/build/
/web/test-coverage/

###> symfony/framework-bundle ###
/.env.local
/.env.local.php
/.env.*.local
/config/secrets/prod/prod.decrypt.private.php
/public/bundles/
/var/
/vendor/
###< symfony/framework-bundle ###

###> phpunit/phpunit ###
/phpunit.xml
/public/test-coverage/
.phpunit.result.cache
###< phpunit/phpunit ###
###> symfony/phpunit-bridge ###
.phpunit.result.cache
/phpunit.xml
###< symfony/phpunit-bridge ###

###> phpstan/phpstan ###
phpstan.neon
###< phpstan/phpstan ###
.env
134 changes: 87 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,83 +1,97 @@
# ToDo & Co Application

[![Symfony 3.4 CI Pipeline](https://github.com/Mike031289/ToDo-Co/actions/workflows/ci.yml/badge.svg?branch=develop)](https://github.com/Mike031289/ToDo-Co/actions/workflows/ci.yml)
[![Symfony 5.4 CI Pipeline](https://github.com/Mike031289/ToDo-Co/actions/workflows/ci.yml/badge.svg?branch=develop)](https://github.com/Mike031289/ToDo-Co/actions/workflows/ci.yml)

Base du projet #8 : Améliorez un projet existant
Base du projet **OpenClassrooms #8** : _Améliorez un projet existant_
https://openclassrooms.com/projects/ameliorer-un-projet-existant-1

---

## 📝 About The Project
# 📝 About the Project

This repository is dedicated to the modernization of the **ToDo & Co** web application.

The main objective of this project is to take over an existing legacy codebase (**Symfony 3.1 / PHP 5.5.9**), perform a thorough code quality audit, fix critical technical debt, and implement new technical requirementsincluding advanced user management, security policies, and an exhaustive automated testing suite (PHPUnit).
The main objective of this project is to take over an existing legacy codebase (**Symfony 3.1 / PHP 5.5.9**), perform a thorough code quality audit, eliminate technical debt, and implement new technical requirements, including advanced user management, security policies, and a comprehensive automated testing suite using **PHPUnit**.

### 🚀 Modernization Goals Achieved
## 🚀 Modernization Goals Achieved

- **Framework Upgrade:** Migrated the legacy application to **Symfony 3.4** and **PHP 7.4** to ensure stability and long-term dependency support.
- **Security Overhaul:** Implemented multi-level roles, isolated task ownership, and resolved security vulnerabilities using Symfony **Voters**.
- **Quality Assurance:** Built a comprehensive automated testing suite with **PHPUnit**, covering controllers, forms, and business logic.
- **CI/CD Pipeline:** Integrated **GitHub Actions** for continuous integration, including automated tests, static analysis, and code style validation on every push.
- **Framework Upgrade:** Migrated the application from **Symfony 3.1** to **Symfony 5.4 LTS** and from **PHP 5.5.9** to **PHP 8.1**.
- **Security Overhaul:** Introduced multi-level roles, secured task ownership, and protected sensitive actions using Symfony **Voters**.
- **Quality Assurance:** Implemented an extensive automated test suite with **PHPUnit 9.6**, covering controllers, entities, forms, and business logic.
- **CI/CD Pipeline:** Configured **GitHub Actions** to automatically run tests, static analysis, and coding standards validation on every push and pull request.

---

## 🛠️ Tech Stack
# 🛠️ Tech Stack

| Category | Technology |
| :---------------------------- | :---------------------------- |
| **Framework** | Symfony 3.4 |
| **Language** | PHP 7.4 |
| ----------------------------- | ----------------------------- |
| **Framework** | Symfony 5.4 |
| **Language** | PHP 8.1 |
| **Database** | MySQL / MariaDB |
| **Testing** | PHPUnit |
| **Testing** | PHPUnit 9.6 |
| **CI/CD** | GitHub Actions |
| **Static Analysis & Quality** | Codacy, PHPStan, PHP CS Fixer |
| **Migration Tool** | Rector (PHP 8.1 compatible) |
| **Debugging & Profiling** | Xdebug 3.x |

---

## 📖 Project Documentation
# 📖 Project Documentation

To make onboarding and maintenance as smooth as possible, the documentation is split into dedicated guides:
To simplify onboarding and long-term maintenance, the documentation is organized into dedicated guides.

### 📘 Installation & Contribution Guide (`CONTRIBUTING.md`)
## 📘 Installation & Contribution Guide (`CONTRIBUTING.md`)

- Step-by-step local setup instructions.
- Database configuration and fixtures.
- Git workflow (branch naming and Conventional Commits).
- Commands to run the automated test suite.
This guide includes:

### 🔐 Technical Security & Authentication (`doc/security.md`)
- Local installation instructions
- Database configuration
- Fixture loading
- Git workflow (branch naming and Conventional Commits)
- Commands for running the automated test suite

- Authentication architecture overview.
- Role hierarchy (`ROLE_USER` / `ROLE_ADMIN`).
- Route-level authorization and `TaskVoter` rules.
- Demo accounts for testing.
## 🔐 Technical Security & Authentication (`doc/TECHNICAL_SECURITY.md`)

This document describes:

- Authentication architecture
- Role hierarchy (`ROLE_USER` / `ROLE_ADMIN`)
- Route-level authorization
- Business authorization using `TaskVoter`
- Demo accounts for testing

---

## 🚦 Quick Start (Local Setup)
# 🚦 Quick Start

For complete installation instructions, refer to **CONTRIBUTING.md**.
For complete installation instructions, see **CONTRIBUTING.md**.

### 1. Install dependencies
## 1. Install dependencies

```bash
composer install
```

### 2. Configure the database
## 2. Configure the database

Update your database connection settings in your `.env` file (or your local environment configuration).

During installation, provide your local database credentials when `parameters.yml` is generated.
Example:

```dotenv
DATABASE_URL="mysql://user:password@127.0.0.1:3306/todo"
```

### 3. Create the database and load fixtures
## 3. Create the database and load fixtures

```bash
php bin/console doctrine:database:create
php bin/console doctrine:schema:create
php bin/console doctrine:fixtures:load --no-interaction
```

### 4. Start the local server
## 4. Start the local server

```bash
php bin/console server:start
Expand All @@ -91,35 +105,61 @@ http://127.0.0.1:8000

---

## 🧪 Running Tests
# 🧪 Running Tests & Code Coverage

## Run the complete test suite

```bash
vendor/bin/phpunit
```

## Run a specific test class

Task entity tests:

```bash
vendor/bin/phpunit tests/Entity/TaskTest.php
```

Run the complete automated test suite:
Task controller tests:

```bash
php bin/phpunit
vendor/bin/phpunit tests/Controller/TaskControllerTest.php
```

Run a specific test file (example: Task controller security tests):
## Generate a code coverage report

```bash
php bin/phpunit tests/AppBundle/Controller/TaskControllerTest.php
php -d xdebug.mode=coverage vendor/bin/phpunit --coverage-text
```

---

## 📊 Quality Audit
# 📊 Quality Audit

Code quality is continuously monitored to ensure maintainability and compliance with Symfony best practices.

## ✅ Coding Standards

Coding style follows **PSR-12** and is automatically enforced using **PHP CS Fixer**.

## 🔍 Static Analysis

Code quality is continuously monitored to keep the project maintainable and compliant with Symfony best practices.
**PHPStan** is used to detect:

### ✅ Coding Standards
- Type inconsistencies
- Potential runtime errors
- Dead code
- Common programming mistakes

- PSR-12 compatibility enforced with **PHP CS Fixer**.
before deployment.

### 🔍 Static Analysis
## 🔄 Continuous Integration

- **PHPStan** is used to detect type inconsistencies and potential runtime issues before deployment.
Every push and pull request automatically triggers the GitHub Actions pipeline, which performs:

### 🔄 Continuous Integration
- PHPUnit test execution
- PHP CS Fixer validation
- PHPStan static analysis

- **GitHub Actions** automatically executes tests, code style checks, and static analysis.
- **Codacy** reviews every Pull Request to monitor technical debt and maintain code quality.
Additionally, **Codacy** continuously reviews pull requests to monitor technical debt and maintain overall code quality.
7 changes: 0 additions & 7 deletions app/.htaccess

This file was deleted.

7 changes: 0 additions & 7 deletions app/AppCache.php

This file was deleted.

Loading
Loading