Skip to content

Commit

Permalink
Merge pull request #165 from marinaglancy/phpunitwarnings
Browse files Browse the repository at this point in the history
PHPUnit should fail if there are warnings
  • Loading branch information
stronk7 authored Apr 22, 2022
2 parents a9e6f29 + 2393b6f commit 4ee9e55
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,6 @@ jobs:
"$MOODLE_BRANCH" != 'master' -a \
"$MOODLE_BRANCH" != 'MOODLE_400_STABLE' ]
moodle-plugin-ci phpdoc
moodle-plugin-ci phpunit --verbose --coverage-text
moodle-plugin-ci phpunit --verbose --coverage-text --fail-on-warning
moodle-plugin-ci behat --profile default
moodle-plugin-ci behat --profile chrome
2 changes: 1 addition & 1 deletion .travis.dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ script:
- moodle-plugin-ci savepoints
- moodle-plugin-ci mustache
- moodle-plugin-ci grunt
- moodle-plugin-ci phpdoc
- moodle-plugin-ci phpdoc --fail-on-warning
- moodle-plugin-ci phpunit
- moodle-plugin-ci behat
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ script:
"$MOODLE_BRANCH" != 'MOODLE_310_STABLE' -a \
"$MOODLE_BRANCH" != 'MOODLE_39_STABLE' ]
- moodle-plugin-ci phpdoc
- moodle-plugin-ci phpunit --coverage-text
- moodle-plugin-ci phpunit --coverage-text --fail-on-warning
- moodle-plugin-ci behat --profile default
- moodle-plugin-ci behat --profile chrome

Expand Down
2 changes: 2 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
The format of this change log follows the advice given at [Keep a CHANGELOG](http://keepachangelog.com).

## [Unreleased]
### Changed
- It is possible to specify more test execution options to the 'phpunit' command, such as "--fail-on-warning"

## [3.2.5] - 2022-03-31
### Changed
Expand Down
38 changes: 37 additions & 1 deletion docs/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -1735,7 +1735,7 @@ Run PHPUnit on a plugin

### Usage

* `phpunit [-m|--moodle MOODLE] [--coverage-text] [--coverage-clover] [--] <plugin>`
* `phpunit [-m|--moodle MOODLE] [--coverage-text] [--coverage-clover] [--fail-on-incomplete] [--fail-on-risky] [--fail-on-skipped] [--fail-on-warning] [--] <plugin>`

Run PHPUnit on a plugin

Expand Down Expand Up @@ -1778,6 +1778,42 @@ Generate code coverage report in Clover XML format
* Is multiple: no
* Default: `false`

#### `--fail-on-incomplete`

Treat incomplete tests as failures

* Accept value: no
* Is value required: no
* Is multiple: no
* Default: `false`

#### `--fail-on-risky`

Treat risky tests as failures

* Accept value: no
* Is value required: no
* Is multiple: no
* Default: `false`

#### `--fail-on-skipped`

Treat skipped tests as failures

* Accept value: no
* Is value required: no
* Is multiple: no
* Default: `false`

#### `--fail-on-warning`

Treat tests with warnings as failures

* Accept value: no
* Is value required: no
* Is multiple: no
* Default: `false`

#### `--help|-h`

Display this help message
Expand Down
2 changes: 1 addition & 1 deletion gha.dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ jobs:

- name: PHPUnit tests
if: ${{ always() }}
run: moodle-plugin-ci phpunit
run: moodle-plugin-ci phpunit --fail-on-warning

- name: Behat features
if: ${{ always() }}
Expand Down
11 changes: 10 additions & 1 deletion src/Command/PHPUnitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ protected function configure()
$this->setName('phpunit')
->setDescription('Run PHPUnit on a plugin')
->addOption('coverage-text', null, InputOption::VALUE_NONE, 'Generate and print code coverage report in text format')
->addOption('coverage-clover', null, InputOption::VALUE_NONE, 'Generate code coverage report in Clover XML format');
->addOption('coverage-clover', null, InputOption::VALUE_NONE, 'Generate code coverage report in Clover XML format')
->addOption('fail-on-incomplete', null, InputOption::VALUE_NONE, 'Treat incomplete tests as failures')
->addOption('fail-on-risky', null, InputOption::VALUE_NONE, 'Treat risky tests as failures')
->addOption('fail-on-skipped', null, InputOption::VALUE_NONE, 'Treat skipped tests as failures')
->addOption('fail-on-warning', null, InputOption::VALUE_NONE, 'Treat tests with warnings as failures');
}

protected function initialize(InputInterface $input, OutputInterface $output)
Expand Down Expand Up @@ -74,6 +78,11 @@ private function resolveOptions(InputInterface $input)
if ($this->supportsCoverage() && $input->getOption('coverage-clover')) {
$options[] = sprintf('--coverage-clover %s/coverage.xml', getcwd());
}
foreach (['fail-on-warning', 'fail-on-risky', 'fail-on-skipped', 'fail-on-warning'] as $option) {
if ($input->getOption($option)) {
$options[] = '--'.$option;
}
}
if (is_file($this->plugin->directory.'/phpunit.xml')) {
$options[] = sprintf('--configuration %s', $this->plugin->directory);
} else {
Expand Down
6 changes: 3 additions & 3 deletions tests/Fixture/moodle-local_ci/tests/lib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function test_local_ci_add() {
/**
* Test subtraction.
*
* @covers ::local_ci_substract
* @covers ::local_ci_subtract
*/
public function test_local_ci_subtract() {
$this->assertEquals(0, local_ci_subtract(2, 2));
Expand All @@ -63,7 +63,7 @@ public function test_local_ci_subtract() {
/**
* Test math class.
*
* @covers \local_ci\math\add
* @covers \local_ci\math::add
*/
public function test_local_ci_math() {
$math = new \local_ci_math();
Expand All @@ -75,7 +75,7 @@ public function test_local_ci_math() {
/**
* Test math class.
*
* @covers \local_ci\math\add
* @covers \local_ci\math::add
*/
public function test_local_ci_math_class() {
$math = new math();
Expand Down

0 comments on commit 4ee9e55

Please sign in to comment.