* FIX pre-commit PHPStan hook errors on commits with no file in scope phpstan.neon.dist only analyzes htdocs/ and scripts/, but the pre-commit wrapper passed every staged file straight to phpstan regardless of path. A commit touching only files outside that scope (e.g. test/phpunit/) made phpstan exit with "No files found to analyse", failing the hook for reasons unrelated to the change being committed. Filter to htdocs/ and scripts/ first, and skip cleanly when nothing remains. * NEW: Add phpunit test for Opensurveysondage class Add a CRUD test (create/fetch/update/delete) for the Opensurveysondage class, which had no test coverage yet. Note: create()'s return value is not used to identify the created record - Opensurveysondage::create() returns $this->id, but this class never sets $this->id (the real primary key is the caller- supplied $this->id_sondage string), so the return value carries no information. The test uses errors/re-fetch to check success instead. * NEW: Auto-activate module opensurvey in OpensurveysondageTest if needed Activate module opensurvey in setUpBeforeClass() when it is not already enabled, so the test does not depend on the environment's module configuration. Note: this activation is real and persists after the test run - it is not undone by the transaction rollback in tearDownAfterClass(). Activating a module re-runs its SQL install scripts (CREATE/ALTER TABLE), which causes an implicit commit in MySQL/InnoDB, same as an admin enabling it from Setup > Modules would do.
39 lines
1.2 KiB
Bash
Executable file
39 lines
1.2 KiB
Bash
Executable file
#!/bin/bash
|
|
# Copyright (C) 2026 Frédéric France <frederic.france@free.fr>
|
|
|
|
# Wrapper to run 'PHPStan' from pre-commit hook
|
|
# This is very slow so not enabled by default
|
|
# To enable it, create a file ~/.run-phpstan
|
|
# To disable it, remove this file ~/.run-phpstan
|
|
|
|
echo "Running PHPStan on files ~/vendor/bin/phpstan --level=9 -v analyze -a dev/build/phpstan/bootstrap.php $@"
|
|
|
|
# Test presence of file
|
|
if [ ! -f ~/.run-phpstan ]; then
|
|
echo "Skipping PHPStan (file ~/.run-phpstan missing)"
|
|
exit 0
|
|
fi
|
|
|
|
if [ ! -f ~/vendor/bin/phpstan ]; then
|
|
echo "Skipping PHPStan (file ~/vendor/bin/phpstan missing)"
|
|
exit 0
|
|
fi
|
|
|
|
# phpstan.neon.dist only analyzes htdocs/ and scripts/: keep only files under these dirs so a commit
|
|
# that touches only out-of-scope files (test/phpunit/, dev/, doc/, ...) does not make phpstan error
|
|
# out with "No files found to analyse".
|
|
filtered=()
|
|
for f in "$@"; do
|
|
case "$f" in
|
|
htdocs/*|scripts/*) filtered+=("$f") ;;
|
|
esac
|
|
done
|
|
|
|
if [ ${#filtered[@]} -eq 0 ]; then
|
|
echo "Skipping PHPStan (no file in scope: htdocs/ or scripts/)"
|
|
exit 0
|
|
fi
|
|
|
|
~/vendor/bin/phpstan --level=9 -v analyze -a dev/build/phpstan/bootstrap.php "${filtered[@]}"
|
|
|
|
exit $?
|