- PHP API for order creation
- SQLite database for persistence
- PHPUnit tests for API endpoints
- Docker
.
├── scripts/
│ ├── build.sh # Install dependencies and initialize the database
│ ├── run.sh # Start the Apache server on port 9090
│ └── test.sh # Run syntax checks and PHPUnit tests
├── src/ # PHP source code (API, services, config)
├── tests/ # PHPUnit test cases
├── Dockerfile # Docker build instructions
└── README.md
The SQLite database consists of the following tables:
-
vat_rates
vat_rate_id
name
rate
-
products
product_id
price
vat_rate_id
-
orders
order_id
price
vat
-
order_items
order_id
product_id
discount_percentage
Sample Data:
On first initialization, the database is seeded with:
- One VAT rate (
default
, 10%) - Three products:
- Product 1: price 2.00
- Product 2: price 1.50
- Product 3: price 3.00
POST /api/order/create
Request body:
{
"order": {
"items": [
{ "product_id": 1, "quantity": 1 },
{ "product_id": 2, "quantity": 5 },
{ "product_id": 3, "quantity": 1 }
]
}
}
Expected response:
{
"order_id": 3412433,
"order_price": 12.50,
"order_vat": 1.25,
"items": [
{
"product_id": 1,
"quantity": 1,
"price": 2.00,
"vat": 0.20
},
{
"product_id": 2,
"quantity": 5,
"price": 7.50,
"vat": 0.75
},
{
"product_id": 3,
"quantity": 1,
"price": 3.00,
"vat": 0.30
}
]
}
-
build.sh
Installs Composer dependencies, ensures the SQLite database directory exists, and initializes the database schema and sample data. -
test.sh
Runs PHP syntax checks on all source files and executes PHPUnit tests. -
run.sh
Configures Apache to listen on port 9090 and starts the server in the foreground.
docker build -t mytest .
docker run -v $(pwd):/mnt -p 9090:9090 -w /mnt mytest ./scripts/build.sh
docker run -v $(pwd):/mnt -p 9090:9090 -w /mnt mytest ./scripts/test.sh
docker run -v $(pwd):/mnt -p 9090:9090 -w /mnt mytest ./scripts/run.sh
- The API will be available at http://localhost:9090.
You can test the API using curl
:
curl -X POST localhost:9090/api/order/create \
-H "Content-Type: application/json" \
-d '{
"order": {
"items": [
{
"product_id": 1,
"quantity": 1
},
{
"product_id": 2,
"quantity": 5
},
{
"product_id": 3,
"quantity": 1
}
]
}
}'
Tests are written with PHPUnit and cover both successful and error scenarios for the order creation API.
To run the tests, use the test.sh
script as shown above.
Note:
All scripts are intended to be run inside the Docker container as shown above.
The -v $(pwd):/mnt
flag mounts your project directory into the container, and -w /mnt
sets it as the working directory.