From 447332a7acc60d6322bd8668ce7b4688c416b069 Mon Sep 17 00:00:00 2001 From: Eirik Stanghelle Morland Date: Mon, 3 Jun 2024 13:21:41 +0200 Subject: [PATCH] Document pre-commit --- pre-commit.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 pre-commit.md diff --git a/pre-commit.md b/pre-commit.md new file mode 100644 index 0000000..fe66616 --- /dev/null +++ b/pre-commit.md @@ -0,0 +1,19 @@ +# Running tests as pre-commit hooks + +If you want to run some of the tests as git hooks to avoid comitting "bad" code, you can do that. It would probably make most sense to only run static tests. + +Usually static tests are run with the command `composer test-static`. To run this as a git hook you can simply add this file to a file called `.git/hooks/pre-commit` in your project: + +```sh +#!/bin/sh + +composer test-static +``` + +If you think that takes too long, and you just want to run code style checks with phpcs, you can instead change it to something like this: + +```sh +#!/bin/sh + +vendor/bin/phpcs -pn +```