This is a template of PHP 8 project. You can use it to start with your own PHP project. Inside this template you will find:
- composer file with basic libraries defined,
- configuration file for php-cs-fixer,
- configuration file for PHPUnit,
- configuration file for Kahlan,
- code samples that you can start with.
This template use Composer for dependency management. To download all dependent code you need call this command:
composer install
Or if you want tu update (outdated packages):
composer update
- "/src" - your code goes here
- "/test" - here yo will put all of your phpunit tests
- "/spec" - and this is a place for kahlan spec files
Directories "vendor" and "docs" are technical ones and you don't need to make any changes in them.
Remember to change your namespace. This project template use "WeBee" namespace.
To run all tests execute bellow command:
./vendor/bin/phpunit
According to template configuration this command will also generate coverage report. It will be placed in "docs/coverage-report" directory.
WARNING: Code coverage needs to be enabled in php.ini by setting 'xdebug.mode' to 'coverage'.
To run all spec files execute this command:
./vendor/bin/kahlan
To fix all code standards violations run below command:
./vendor/bin/php-cs-fixer fix
If you only want to see all violations just run this command:
./vendor/bin/php-cs-fixer --dry-run --diff fix
- Download Nix package manager: https://nixos.org/download.html
- Turn on flakes support: https://nixos.wiki/wiki/Flakes#Non-NixOS
- Install nix-direnv:
nix-env -f '<nixpkgs>' -iA nix-direnv
- Start a new shell, go to project root and run:
direnv allow
Assuming here you've got installed nix, direnv, and nix-direnv.
USER=<your-github-username>
NAME=<your-new-repo-name-here>
git clone [email protected]:volodhrim/php8-template.git "${NAME}"
direnv allow
git remote rename origin old-origin
git remote add origin "[email protected]:${USER}/${NAME}.git"
git branch -M master
git push -u origin master
- run
menu
to see a list of inbuilt shorthand commands you can add yourself
TODO: move this thing to use the devshell.toml file
TODO: call this origin something like devtemplate
and set a command to pull regularly
Big thanks to the guy I've originally stole this thing from.