Skip to content

Commit

Permalink
RulesetTest: fix the test script to be able to handle 0 values
Browse files Browse the repository at this point in the history
Turns out the test script was not set up to be able to deal with `0` values and would throw a very informative "_Expected 0 errors, found 0 on line 7._" error in such a case.

Fixed now.
  • Loading branch information
jrfnl committed Jul 21, 2020
1 parent d19f289 commit 6980e12
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/RulesetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ private function check_missing_expected_values() {
}

foreach ( $lines as $line_number => $expected_count_of_type_violations ) {
if ( 0 === $expected_count_of_type_violations ) {
continue;
}

if ( ! isset( $this->{$type}[ $line_number ] ) ) {
$this->error_warning_message( $expected_count_of_type_violations, $type, 0, $line_number );
} elseif ( $this->{$type}[ $line_number ] !== $expected_count_of_type_violations ) {
Expand All @@ -237,6 +241,10 @@ private function check_missing_expected_values() {
private function check_unexpected_values() {
foreach ( [ 'errors', 'warnings' ] as $type ) {
foreach ( $this->$type as $line_number => $actual_count_of_type_violations ) {
if ( 0 === $actual_count_of_type_violations ) {
continue;
}

if ( ! isset( $this->expected[ $type ][ $line_number ] ) ) {
$this->error_warning_message( 0, $type, $actual_count_of_type_violations, $line_number );
} elseif ( $actual_count_of_type_violations !== $this->expected[ $type ][ $line_number ] ) {
Expand Down

0 comments on commit 6980e12

Please sign in to comment.