Skip to content

Commit

Permalink
Very simple integration tests to verify that command line works ok
Browse files Browse the repository at this point in the history
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: shivammathur/setup-php#450
  • Loading branch information
stronk7 committed Jan 12, 2023
1 parent 06705e8 commit 88ba479
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
16 changes: 15 additions & 1 deletion .github/workflows/phpcs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 > 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 > 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 > output.txt || [[ $? = 0 ]]
4 changes: 4 additions & 0 deletions moodle/Tests/fixtures/integration_test_ci.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php
// phpcs:disable moodle.Files
defined('MOODLE_INTERNAL') || die(); // Make this always the 1st line in all CS fixtures.
$arr ['wrong'] = $value;

0 comments on commit 88ba479

Please sign in to comment.