A skeleton for creating applications with CakePHP 4.x.
All code is licensed under MIT License
Run from docker-compose:
docker-compose -f ./docker-compose-dev.yml up -d
Connect as root
to the database launched using docker-compose (e.g. you can run exec on the container from nginx) and create a new default
db for the project
(check config/app_local.php
file for the credentials)
Connect to the nginx container using exec and run composer (do not run as root, but in order to set folder permissions root may be needed)
cd /var/www/cplatform/public/app_rest/
su composeruser
composer install
The local path is the location of this readme file and it should be mapped to /var/www/cplatform/public
When running test use /var/www/cplatform/public/app_rest/phpunit.xml.dist
as default configuration file.
Also add /var/www/cplatform/public/app_rest/vendor/autoload.php
as a default autoload file
- Connect to the container using exec
- Navigate to the main path with
cd /var/www/cplatform/public/app_rest
- Avoid running commands as root (since it can cause permission problems), change the user with:
su composeruser
You can run tests using phpunit command: vendor/bin/phpunit -c ../app_rest/phpunit.xml.dist
But using an IDE is desirable (e.g. PhpStorm)
Generate test coverage with: vendor/bin/phpunit --coverage-html ./webroot/coverage/*
Follow cakephp plugin documentation:
- Bake a plugin with
bin/cake bake plugin Thename
- Add new directories to
composer.json
and refresh autoload cache withcomposer dumpautoload
(remind the team to run this in every local laptop, or they may get errors) - Remember to add the new route to tests in
phpunit.xml
- Add new plugin to
migrationList()
inapp_rest/config/bootstrap.php
- Add new plugin to
bootstrap()
inapp_rest/src/Application.php
Migrations should be the only way to perform changes in the database schema
More info about phinx and the migration plugin on cake book
# create a new migration called 'CreateUsers'
bin/cake bake migration CreateUsers
# execute the migration on the db
bin/cake migrations migrate
# revert the migration on the db
bin/cake migrations rollback
# create new seeds
bin/cake bake seed Users
# run seeder
bin/cake migrations seed
# run specific seeder class
bin/cake migrations seed --seed UsersSeed