SuperDemo is a demonstration Symfony 6.4 project inspired by document management workflows used in modern business applications.
The project implements a document life cycle using Symfony Workflow (State Machine), REST API and PHPUnit tests.
Main features:
- Customer management;
- Document creation;
- Document state management using Symfony Workflow;
- REST API;
- Docker-based development environment;
- Functional and unit testing with PHPUnit.
- PHP 8.2
- Symfony 6.4 (LTS)
- Doctrine ORM
- Doctrine Migrations
- MySQL 8
- Symfony Workflow (State Machine)
- PHPUnit 11
- PHPStan 2
- Docker & Docker Compose
- REST API
A document can have only one state at a time.
validate
draft ----------------------------> validated
| |
| |
| cancel | send
| |
v v
cancelled sent
|
|
| complete
|
v
completed
Allowed transitions:
| Transition | From | To |
|---|---|---|
| validate | draft | validated |
| send | validated | sent |
| complete | sent | completed |
| cancel | draft, validated, sent | cancelled |
Examples:
- draft -> validated -> sent -> completed
- draft -> cancelled
- validated -> cancelled
- sent -> cancelled
The following transition is not allowed:
draft -> completed
In this case the API returns:
409 Conflict
src
├── Controller
│ ├── CustomerController.php
│ └── DocumentController.php
│
├── Entity
│ ├── Customer.php
│ └── Document.php
│
├── Enum
│ └── DocumentType.php
│
├── Exception
│ └── InvalidDocumentTransitionException.php
│
└── Service
└── DocumentService.php
tests
├── Controller
├── Service
└── Workflow
Start Docker containers:
docker compose up -dCheck running containers:
docker compose psEnter PHP container:
docker compose exec php shcomposer installIf required:
npm installCreate the database:
php bin/console doctrine:database:createRun migrations:
php bin/console doctrine:migrations:migrateCheck the schema:
php bin/console doctrine:schema:validateRun all tests:
php bin/phpunitRun Workflow tests:
php bin/phpunit tests/WorkflowRun Service tests:
php bin/phpunit tests/ServiceRun Controller tests:
php bin/phpunit tests/ControllerPOST /api/customers
Request:
{
"name":"Example s.r.o.",
"email":"office@example.sk"
}Response:
{
"id":1,
"name":"Example s.r.o.",
"email":"office@example.sk"
}POST /api/documents
Request:
{
"title":"Service contract",
"type":"contract",
"customerId":1
}GET /api/documents/{id}
Example:
GET /api/documents/1
PATCH /api/documents/{id}/validate
Example:
PATCH /api/documents/1/validate
PATCH /api/documents/{id}/send
Example:
PATCH /api/documents/1/send
PATCH /api/documents/{id}/complete
Example:
PATCH /api/documents/1/complete
PATCH /api/documents/{id}/cancel
Example:
PATCH /api/documents/1/cancel
| Status | Description |
|---|---|
| 200 | Success |
| 201 | Resource created |
| 400 | Invalid JSON payload |
| 404 | Resource was not found |
| 409 | Invalid document transition |
| 422 | Validation error |
The project currently contains:
- Workflow tests;
- Service layer tests;
- Functional API tests.
Covered scenarios include:
- customer creation;
- document creation;
- document life cycle;
- allowed workflow transitions;
- forbidden transitions;
- invalid JSON payloads;
- validation errors;
- unknown customers;
- unknown documents;
- API error handling.
All tests must pass successfully before submitting changes.
php bin/phpunit
Run static analysis:
composer analyse