Skip to content

Commit 4ee9e55

Browse files
authored
Merge pull request #165 from marinaglancy/phpunitwarnings
PHPUnit should fail if there are warnings
2 parents a9e6f29 + 2393b6f commit 4ee9e55

File tree

8 files changed

+56
-9
lines changed

8 files changed

+56
-9
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,6 @@ jobs:
101101
"$MOODLE_BRANCH" != 'master' -a \
102102
"$MOODLE_BRANCH" != 'MOODLE_400_STABLE' ]
103103
moodle-plugin-ci phpdoc
104-
moodle-plugin-ci phpunit --verbose --coverage-text
104+
moodle-plugin-ci phpunit --verbose --coverage-text --fail-on-warning
105105
moodle-plugin-ci behat --profile default
106106
moodle-plugin-ci behat --profile chrome

.travis.dist.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ script:
4545
- moodle-plugin-ci savepoints
4646
- moodle-plugin-ci mustache
4747
- moodle-plugin-ci grunt
48-
- moodle-plugin-ci phpdoc
48+
- moodle-plugin-ci phpdoc --fail-on-warning
4949
- moodle-plugin-ci phpunit
5050
- moodle-plugin-ci behat

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ script:
5959
"$MOODLE_BRANCH" != 'MOODLE_310_STABLE' -a \
6060
"$MOODLE_BRANCH" != 'MOODLE_39_STABLE' ]
6161
- moodle-plugin-ci phpdoc
62-
- moodle-plugin-ci phpunit --coverage-text
62+
- moodle-plugin-ci phpunit --coverage-text --fail-on-warning
6363
- moodle-plugin-ci behat --profile default
6464
- moodle-plugin-ci behat --profile chrome
6565

docs/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
99
The format of this change log follows the advice given at [Keep a CHANGELOG](http://keepachangelog.com).
1010

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

1315
## [3.2.5] - 2022-03-31
1416
### Changed

docs/CLI.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1735,7 +1735,7 @@ Run PHPUnit on a plugin
17351735

17361736
### Usage
17371737

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

17401740
Run PHPUnit on a plugin
17411741

@@ -1778,6 +1778,42 @@ Generate code coverage report in Clover XML format
17781778
* Is multiple: no
17791779
* Default: `false`
17801780

1781+
#### `--fail-on-incomplete`
1782+
1783+
Treat incomplete tests as failures
1784+
1785+
* Accept value: no
1786+
* Is value required: no
1787+
* Is multiple: no
1788+
* Default: `false`
1789+
1790+
#### `--fail-on-risky`
1791+
1792+
Treat risky tests as failures
1793+
1794+
* Accept value: no
1795+
* Is value required: no
1796+
* Is multiple: no
1797+
* Default: `false`
1798+
1799+
#### `--fail-on-skipped`
1800+
1801+
Treat skipped tests as failures
1802+
1803+
* Accept value: no
1804+
* Is value required: no
1805+
* Is multiple: no
1806+
* Default: `false`
1807+
1808+
#### `--fail-on-warning`
1809+
1810+
Treat tests with warnings as failures
1811+
1812+
* Accept value: no
1813+
* Is value required: no
1814+
* Is multiple: no
1815+
* Default: `false`
1816+
17811817
#### `--help|-h`
17821818

17831819
Display this help message

gha.dist.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ jobs:
103103

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

108108
- name: Behat features
109109
if: ${{ always() }}

src/Command/PHPUnitCommand.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ protected function configure()
3030
$this->setName('phpunit')
3131
->setDescription('Run PHPUnit on a plugin')
3232
->addOption('coverage-text', null, InputOption::VALUE_NONE, 'Generate and print code coverage report in text format')
33-
->addOption('coverage-clover', null, InputOption::VALUE_NONE, 'Generate code coverage report in Clover XML format');
33+
->addOption('coverage-clover', null, InputOption::VALUE_NONE, 'Generate code coverage report in Clover XML format')
34+
->addOption('fail-on-incomplete', null, InputOption::VALUE_NONE, 'Treat incomplete tests as failures')
35+
->addOption('fail-on-risky', null, InputOption::VALUE_NONE, 'Treat risky tests as failures')
36+
->addOption('fail-on-skipped', null, InputOption::VALUE_NONE, 'Treat skipped tests as failures')
37+
->addOption('fail-on-warning', null, InputOption::VALUE_NONE, 'Treat tests with warnings as failures');
3438
}
3539

3640
protected function initialize(InputInterface $input, OutputInterface $output)
@@ -74,6 +78,11 @@ private function resolveOptions(InputInterface $input)
7478
if ($this->supportsCoverage() && $input->getOption('coverage-clover')) {
7579
$options[] = sprintf('--coverage-clover %s/coverage.xml', getcwd());
7680
}
81+
foreach (['fail-on-warning', 'fail-on-risky', 'fail-on-skipped', 'fail-on-warning'] as $option) {
82+
if ($input->getOption($option)) {
83+
$options[] = '--'.$option;
84+
}
85+
}
7786
if (is_file($this->plugin->directory.'/phpunit.xml')) {
7887
$options[] = sprintf('--configuration %s', $this->plugin->directory);
7988
} else {

tests/Fixture/moodle-local_ci/tests/lib_test.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function test_local_ci_add() {
5252
/**
5353
* Test subtraction.
5454
*
55-
* @covers ::local_ci_substract
55+
* @covers ::local_ci_subtract
5656
*/
5757
public function test_local_ci_subtract() {
5858
$this->assertEquals(0, local_ci_subtract(2, 2));
@@ -63,7 +63,7 @@ public function test_local_ci_subtract() {
6363
/**
6464
* Test math class.
6565
*
66-
* @covers \local_ci\math\add
66+
* @covers \local_ci\math::add
6767
*/
6868
public function test_local_ci_math() {
6969
$math = new \local_ci_math();
@@ -75,7 +75,7 @@ public function test_local_ci_math() {
7575
/**
7676
* Test math class.
7777
*
78-
* @covers \local_ci\math\add
78+
* @covers \local_ci\math::add
7979
*/
8080
public function test_local_ci_math_class() {
8181
$math = new math();

0 commit comments

Comments
 (0)