Skip to content

Commit 8ade71f

Browse files
authored
Merge pull request #247 from woocommerce/25-02/fix/ignore-more-deprecation-warnings
Adds ignoring to the log parsing for some common deprecation warnings
2 parents 6decfa3 + f1fb7fb commit 8ade71f

12 files changed

+670
-187
lines changed

src/src/LocalTests/PrepareDebugLog.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,25 @@ public function prepare_debug_log( string $debug_log_file, string $new_debug_log
6868
continue;
6969
}
7070

71+
// Some compatbility extension set issues.
72+
73+
// Ignore a deprecation warning from Jetpack about itself.
74+
$is_jetpack_geo_deprecation = stripos( $line, 'Class Jetpack_Geo_Location is' ) !== false;
75+
76+
// Ignore a deprecated core filter for now, since subs and payments both include it in shared code.
77+
// Only if we're not testing one of those though.
78+
$is_woocommerce_get_price_deprecation = stripos( $line, 'Use woocommerce_product_get_price instead' ) !== false;
79+
$is_testing_payments_or_subs = in_array( $sut_slug, [ 'woocommerce-payments', 'woocommerce-subscriptions' ], true );
80+
81+
if (
82+
$is_jetpack_geo_deprecation
83+
|| ( $is_woocommerce_get_price_deprecation && ! $is_testing_payments_or_subs )
84+
) {
85+
continue;
86+
}
87+
88+
// End compatibility extension set issues.
89+
7190
/*
7291
* If we are running PHP 8+ on WordPress 6.1 or lower, ignore the following notices.
7392
* @link https://core.trac.wordpress.org/ticket/54504

src/tests/PartnerManagementTest.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,27 @@ protected function get_snapshot_friendly_cache(): string {
5050
* suitable for snapshot testing.
5151
*/
5252

53-
return preg_replace( '#"expire":\s?\d+,#', '"expire": 1234567890,', $json );
53+
$json = preg_replace( '#"expire":\s?\d+,#', '"expire": 1234567890,', $json );
54+
55+
// Normalize known keys if the value looks like a version.
56+
$version_keys = '/"(wordpress_version|woocommerce_version|stable|rc|rc_unsynced|default|playwright_version)":\s?"([^"]+)"/';
57+
58+
$json = preg_replace_callback( $version_keys, function ( $matches ) {
59+
$key = $matches[1];
60+
$value = $matches[2];
61+
62+
// Simple check: starts with digits, then optionally .digits repeated,
63+
// then optionally a dash with alphanumeric parts (beta, rc, etc).
64+
$isVersion = preg_match( '/^\d+(?:\.\d+)*(?:-[A-Za-z0-9.\-_]+)?$/', $value );
65+
66+
if ( $isVersion ) {
67+
$value = 'X.X.X';
68+
}
69+
70+
return "\"{$key}\": \"{$value}\"";
71+
}, $json );
72+
73+
return $json;
5474
}
5575

5676
public function test_add_partner() {

src/tests/RunTestsTest.php

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,43 +19,61 @@ public function setUp(): void {
1919
} );
2020
}
2121

22+
protected function get_last_request() {
23+
$request = App::getVar( 'mocked_request' );
24+
25+
if ( ! is_array( $request ) ) {
26+
return $request;
27+
}
28+
29+
if ( ! empty( $request['post_body']['wordpress_version'] ) ) {
30+
$request['post_body']['wordpress_version'] = 'X.X.X';
31+
}
32+
33+
if ( ! empty( $request['post_body']['woocommerce_version'] ) ) {
34+
$request['post_body']['woocommerce_version'] = 'X.X.X';
35+
}
36+
37+
return $request;
38+
}
39+
2240
public function test_run_with_additional_plugins() {
2341
App::setVar( sprintf( 'mock_%s', get_manager_url() . '/wp-json/cd/v1/enqueue-woo-e2e' ), json_encode( [
2442
'test_run_id' => 123456,
2543
'test_results_manager_url' => ''
2644
] ) );
2745

2846
$this->application_tester->run( [
29-
'command' => 'run:woo-e2e',
30-
'woo_extension' => 'foo-extension', // Using slug.
47+
'command' => 'run:woo-e2e',
48+
'woo_extension' => 'foo-extension', // Using slug.
3149
'--additional_plugins' => '456,789', // Using IDs.
3250
], [ 'capture_stderr_separately' => true ] );
3351

3452
$this->assertCommandIsSuccessful( $this->application_tester );
35-
$this->assertMatchesJsonSnapshot( App::getVar( 'mocked_request' ) );
53+
$this->assertMatchesJsonSnapshot( $this->get_last_request() );
3654

3755
$this->application_tester->run( [
38-
'command' => 'run:woo-e2e',
39-
'woo_extension' => '123', // Using ID.
56+
'command' => 'run:woo-e2e',
57+
'woo_extension' => '123', // Using ID.
4058
'--additional_plugins' => 'bar-extension,baz-extension', // Using Slugs.
4159
], [ 'capture_stderr_separately' => true ] );
4260

4361
// If this fails, debug "$this->application_tester->getDisplay()".
4462
$this->assertCommandIsSuccessful( $this->application_tester );
45-
$this->assertMatchesJsonSnapshot( App::getVar( 'mocked_request' ) );
63+
$this->assertMatchesJsonSnapshot( $this->get_last_request() );
4664

4765
$this->application_tester->run( [
48-
'command' => 'run:woo-e2e',
49-
'woo_extension' => 'foo-extension', // Using ID.
66+
'command' => 'run:woo-e2e',
67+
'woo_extension' => 'foo-extension', // Using ID.
5068
'--additional_plugins' => '456,baz-extension', // Using mixed.
5169
], [ 'capture_stderr_separately' => true ] );
5270

5371
$this->assertCommandIsSuccessful( $this->application_tester );
54-
$this->assertMatchesJsonSnapshot( App::getVar( 'mocked_request' ) );
72+
$this->assertMatchesJsonSnapshot( $this->get_last_request() );
5573

5674
$this->application_tester->run( [
57-
'command' => 'run:woo-e2e',
58-
'woo_extension' => 'foo-extension',
75+
'command' => 'run:woo-e2e',
76+
'woo_extension' => 'foo-extension',
5977
'--additional_plugins' => '1234567890', // If the user passes an invalid ID, the Manager should flag that.
6078
], [ 'capture_stderr_separately' => true ] );
6179

@@ -73,7 +91,7 @@ public function test_run_with_additional_plugins_invalid() {
7391
'woo_extension' => 'non-existing-extension',
7492
], [ 'capture_stderr_separately' => true ] );
7593
} catch ( \Exception $e ) {
76-
$this->assertStringContainsString('Could not find Woo Extension with slug non-existing-extension.', $e->getMessage() );
94+
$this->assertStringContainsString( 'Could not find Woo Extension with slug non-existing-extension.', $e->getMessage() );
7795

7896
throw $e;
7997
}

0 commit comments

Comments
 (0)