From 3ba2d5eca1c4b9f7c81876f19a72ef472e2845fb Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Thu, 12 Jan 2023 16:27:03 +0100 Subject: [PATCH] Very simple integration tests to verify that command line works ok As far as unit tests don't use the command line tools (phpcs, phpcbf) they can be passing ok while the tools have some other problem (say php X.Y compatibility or whatever). These tests just ensure that the command line tools are executed once, against a simple fixture file and results are the expected ones (we have used very simple shell exit codes checks, that's enough for now). Also note that, iby default, the php action comes with production php.ini settings, so error levels and output are not the best for CIs. Hence, let's enable them here. Reference: https://github.com/shivammathur/setup-php/issues/450 --- .github/workflows/phpcs.yml | 16 +++++++++++++++- moodle/Tests/fixtures/integration_test_ci.php | 4 ++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 moodle/Tests/fixtures/integration_test_ci.php diff --git a/.github/workflows/phpcs.yml b/.github/workflows/phpcs.yml index 58a9e08..f2e736d 100644 --- a/.github/workflows/phpcs.yml +++ b/.github/workflows/phpcs.yml @@ -22,7 +22,7 @@ jobs: with: php-version: ${{ matrix.php }} extensions: ${{ matrix.extensions }} - ini-values: pcov.directory=moodle + ini-values: pcov.directory=moodle, error_reporting=-1, display_errors=On coverage: pcov tools: composer @@ -46,3 +46,17 @@ jobs: - name: Test coverage run: ./vendor/bin/phpunit-coverage-check -t 80 clover.xml + + - name: Integration tests + if: ${{ always() }} + run: | + # There is one failure (exit with error) + vendor/bin/phpcs --standard=moodle moodle/Tests/fixtures/integration_test_ci.php | tee output.txt || [[ $? = 1 ]] + grep -q "PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY" output.txt + + # The failure is fixed (exit with error) + vendor/bin/phpcbf --standard=moodle moodle/Tests/fixtures/integration_test_ci.php | tee output.txt || [[ $? = 1 ]] + grep -q "A TOTAL OF 1 ERROR WERE FIXED IN 1 FILE!" output.txt + + # So, there isn't any failure any more (exit without error) + vendor/bin/phpcs --standard=moodle moodle/Tests/fixtures/integration_test_ci.php | tee output.txt && [[ $? = 0 ]] diff --git a/moodle/Tests/fixtures/integration_test_ci.php b/moodle/Tests/fixtures/integration_test_ci.php new file mode 100644 index 0000000..fdd4434 --- /dev/null +++ b/moodle/Tests/fixtures/integration_test_ci.php @@ -0,0 +1,4 @@ +