Skip to content

Commit

Permalink
Fix order of tearing down in PHP unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ernilambar committed Jan 10, 2025
1 parent c7348a9 commit 0a4dc34
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ public function test_run_with_invalid_requires_wp_header() {

$errors = $check_result->get_errors();

delete_transient( 'wp_plugin_check_latest_version_info' );

$this->assertNotEmpty( $errors );

$error_items = wp_list_filter( $errors['load.php'][0][0], array( 'code' => 'plugin_header_invalid_requires_wp' ) );

$this->assertCount( 1, $error_items );
$this->assertStringContainsString( 'such as "6.5" or "6.4"', reset( $error_items )['message'] );

delete_transient( 'wp_plugin_check_latest_version_info' );
}

public function test_run_with_valid_requires_plugins_header() {
Expand Down
38 changes: 19 additions & 19 deletions tests/phpunit/tests/Checker/Checks/Plugin_Readme_Check_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,8 @@ public function test_run_with_errors_parser_warnings_with_custom_set_transient_v

$warnings = $check_result->get_warnings();

delete_transient( 'wp_plugin_check_latest_wp_version' );

$this->assertNotEmpty( $warnings );
$this->assertArrayHasKey( 'readme.txt', $warnings );

Expand All @@ -359,8 +361,6 @@ public function test_run_with_errors_parser_warnings_with_custom_set_transient_v
$filtered_items = array_values( $filtered_items );

$this->assertStringContainsString( 'The "Tested up to" field was ignored. This field should only contain a valid WordPress version such as "' . $version . '"', $filtered_items[0]['message'] );

delete_transient( 'wp_plugin_check_latest_wp_version' );
}

public function test_run_with_errors_multiple_parser_warnings_and_empty_ignored_array() {
Expand All @@ -375,6 +375,8 @@ public function test_run_with_errors_multiple_parser_warnings_and_empty_ignored_
$errors = $check_result->get_errors();
$warnings = $check_result->get_warnings();

remove_filter( 'wp_plugin_check_ignored_readme_warnings', '__return_empty_array' );

$this->assertNotEmpty( $warnings );
$this->assertArrayHasKey( 'readme.txt', $warnings );

Expand All @@ -385,8 +387,6 @@ public function test_run_with_errors_multiple_parser_warnings_and_empty_ignored_
$this->assertEquals( 8, $check_result->get_warning_count() );
$this->assertEmpty( $errors );
$this->assertEquals( 0, $check_result->get_error_count() );

remove_filter( 'wp_plugin_check_ignored_readme_warnings', '__return_empty_array' );
}

public function test_filter_readme_warnings_ignored() {
Expand All @@ -406,15 +406,15 @@ static function () use ( $custom_ignores ) {

$result = apply_filters( $filter_name, array() );

$this->assertEquals( $custom_ignores, $result );

// Remove the filter to avoid interfering with other tests.
remove_filter(
$filter_name,
static function () use ( $custom_ignores ) {
return $custom_ignores;
}
);

$this->assertEquals( $custom_ignores, $result );
}

public function test_filter_wp_plugin_check_ignored_readme_warnings_will_return_no_error() {
Expand Down Expand Up @@ -442,18 +442,18 @@ static function () use ( $custom_ignores ) {
$errors = $check_result->get_errors();
$warnings = $check_result->get_warnings();

$this->assertEmpty( $errors );
$this->assertEmpty( $warnings );
$this->assertSame( 0, $check_result->get_error_count() );
$this->assertSame( 0, $check_result->get_warning_count() );

// Remove the filter to avoid interfering with other tests.
remove_filter(
$filter_name,
static function () use ( $custom_ignores ) {
return $custom_ignores;
}
);

$this->assertEmpty( $errors );
$this->assertEmpty( $warnings );
$this->assertSame( 0, $check_result->get_error_count() );
$this->assertSame( 0, $check_result->get_warning_count() );
}

public function test_run_with_errors_upgrade_notice() {
Expand Down Expand Up @@ -485,18 +485,18 @@ public function test_run_with_errors_tested_up_to_latest_plus_two_version() {

$errors = $check_result->get_errors();

delete_transient( 'wp_plugin_check_latest_wp_version' );

$this->assertNotEmpty( $errors );

$filtered_items = wp_list_filter( $errors['readme.md'][0][0], array( 'code' => 'nonexistent_tested_upto_header' ) );

$this->assertCount( 1, $filtered_items );
$this->assertStringContainsString( 'Tested up to: 6.1', $filtered_items[0]['message'] );
$this->assertStringContainsString( 'This version of WordPress does not exist (yet).', $filtered_items[0]['message'] );

delete_transient( 'wp_plugin_check_latest_wp_version' );
}

public function test_run_with_errors_tested_up_to_latest_plus_one_version() {
public function test_run_without_errors_tested_up_to_latest_plus_one_version() {
$version = '6.0'; // Target plugin has "6.1" is readme.

set_transient( 'wp_plugin_check_latest_wp_version', $version );
Expand All @@ -509,12 +509,12 @@ public function test_run_with_errors_tested_up_to_latest_plus_one_version() {

$errors = $check_result->get_errors();

$this->assertCount( 0, wp_list_filter( $errors['readme.md'][0][0], array( 'code' => 'nonexistent_tested_upto_header' ) ) );

delete_transient( 'wp_plugin_check_latest_wp_version' );

$this->assertCount( 0, wp_list_filter( $errors['readme.md'][0][0], array( 'code' => 'nonexistent_tested_upto_header' ) ) );
}

public function test_run_with_errors_tested_up_to_latest_stable_version() {
public function test_run_without_errors_tested_up_to_latest_stable_version() {
$version = '6.1'; // Target plugin has "6.1" is readme.

set_transient( 'wp_plugin_check_latest_wp_version', $version );
Expand All @@ -527,9 +527,9 @@ public function test_run_with_errors_tested_up_to_latest_stable_version() {

$errors = $check_result->get_errors();

$this->assertCount( 0, wp_list_filter( $errors['readme.md'][0][0], array( 'code' => 'nonexistent_tested_upto_header' ) ) );

delete_transient( 'wp_plugin_check_latest_wp_version' );

$this->assertCount( 0, wp_list_filter( $errors['readme.md'][0][0], array( 'code' => 'nonexistent_tested_upto_header' ) ) );
}

public function test_run_without_errors_readme_contributors_warning() {
Expand Down

0 comments on commit 0a4dc34

Please sign in to comment.