From 040ca55c9740381f4ed6ae3edea4385982d9d798 Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Wed, 22 Nov 2023 13:05:55 -0500 Subject: [PATCH] Clean up output from various tests (#34256) Tests shouldn't produce extraneous output to the console, but some of ours were. * packages/blaze: Prints URLs due to not passing `false` for the `$display` parameter to `menu_page_url()`. * packages/connection: `error_log()` output, which we can redirect to /dev/null. * packages/forms: In CI it prints a bunch of "sh: 1: /usr/sbin/sendmail: not found", while locally it doesn't because that exists and it **actually sends mail** (to an example.com address, at least, which has no MX and so is undeliverable). The 'pre_wp_mail' filter easily prevents the sending of mail. * plugins/jetpack: Output from sync, which we can expect as part of the test. --- .../blaze/changelog/fix-unnecessary-test-outputs | 5 +++++ projects/packages/blaze/tests/php/test-blaze.php | 4 ++-- .../changelog/fix-unnecessary-test-outputs | 5 +++++ .../connection/src/class-package-version.php | 2 +- projects/packages/connection/tests/.phpcs.dir.xml | 4 ++++ .../connection/tests/php/test_Server_Sandbox.php | 14 ++++++++++++-- .../forms/changelog/fix-unnecessary-test-outputs | 5 +++++ .../php/contact-form/test-class.contact-form.php | 3 +++ .../jetpack/changelog/fix-unnecessary-test-outputs | 5 +++++ .../php/sync/test_class.jetpack-sync-sender.php | 3 +++ 10 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 projects/packages/blaze/changelog/fix-unnecessary-test-outputs create mode 100644 projects/packages/connection/changelog/fix-unnecessary-test-outputs create mode 100644 projects/packages/connection/tests/.phpcs.dir.xml create mode 100644 projects/packages/forms/changelog/fix-unnecessary-test-outputs create mode 100644 projects/plugins/jetpack/changelog/fix-unnecessary-test-outputs diff --git a/projects/packages/blaze/changelog/fix-unnecessary-test-outputs b/projects/packages/blaze/changelog/fix-unnecessary-test-outputs new file mode 100644 index 0000000000000..ce5ed0982c19d --- /dev/null +++ b/projects/packages/blaze/changelog/fix-unnecessary-test-outputs @@ -0,0 +1,5 @@ +Significance: patch +Type: fixed +Comment: Avoid output in test. No change to the package itself. + + diff --git a/projects/packages/blaze/tests/php/test-blaze.php b/projects/packages/blaze/tests/php/test-blaze.php index a7871ddb9bf6c..f3fa988a38418 100644 --- a/projects/packages/blaze/tests/php/test-blaze.php +++ b/projects/packages/blaze/tests/php/test-blaze.php @@ -146,14 +146,14 @@ public function test_admin_menu_added() { $this->confirm_add_filters_and_actions_for_screen_starts_clean(); // Ensure that no menu is added by default. - $this->assertEmpty( menu_page_url( 'advertising' ) ); + $this->assertEmpty( menu_page_url( 'advertising', false ) ); wp_set_current_user( $this->admin_id ); add_filter( 'jetpack_blaze_enabled', '__return_true' ); Blaze::enable_blaze_menu(); - $this->assertNotEmpty( menu_page_url( 'advertising' ) ); + $this->assertNotEmpty( menu_page_url( 'advertising', false ) ); add_filter( 'jetpack_blaze_enabled', '__return_false' ); } diff --git a/projects/packages/connection/changelog/fix-unnecessary-test-outputs b/projects/packages/connection/changelog/fix-unnecessary-test-outputs new file mode 100644 index 0000000000000..af317f7b9f8e1 --- /dev/null +++ b/projects/packages/connection/changelog/fix-unnecessary-test-outputs @@ -0,0 +1,5 @@ +Significance: patch +Type: fixed +Comment: Avoid `error_log` output in `Test_Server_Sandbox`. No change to the package itself. + + diff --git a/projects/packages/connection/src/class-package-version.php b/projects/packages/connection/src/class-package-version.php index 2e37f4deb2390..f78681e5b351d 100644 --- a/projects/packages/connection/src/class-package-version.php +++ b/projects/packages/connection/src/class-package-version.php @@ -12,7 +12,7 @@ */ class Package_Version { - const PACKAGE_VERSION = '2.0.2'; + const PACKAGE_VERSION = '2.0.3-alpha'; const PACKAGE_SLUG = 'connection'; diff --git a/projects/packages/connection/tests/.phpcs.dir.xml b/projects/packages/connection/tests/.phpcs.dir.xml new file mode 100644 index 0000000000000..46951fe77b37e --- /dev/null +++ b/projects/packages/connection/tests/.phpcs.dir.xml @@ -0,0 +1,4 @@ + + + + diff --git a/projects/packages/connection/tests/php/test_Server_Sandbox.php b/projects/packages/connection/tests/php/test_Server_Sandbox.php index a7d387d32b79f..d2f292b2b867e 100644 --- a/projects/packages/connection/tests/php/test_Server_Sandbox.php +++ b/projects/packages/connection/tests/php/test_Server_Sandbox.php @@ -141,7 +141,12 @@ public function test_server_sandbox( $sandbox_constant, $url, $expected_url, $ex Constants::set_constant( 'JETPACK__SANDBOX_DOMAIN', $sandbox_constant ); $headers = array(); - ( new Server_Sandbox() )->server_sandbox( $url, $headers ); + ini_set( 'error_log', '/dev/null' ); + try { + ( new Server_Sandbox() )->server_sandbox( $url, $headers ); + } finally { + ini_restore( 'error_log' ); + } $this->assertSame( $expected_url, $url ); $this->assertSame( $expected_headers, $headers ); @@ -205,7 +210,12 @@ public function test_server_sandbox_with_xdebug( $url, $expected_url, $add_filte add_filter( 'jetpack_sandbox_add_profile_parameter', '__return_true' ); } - ( new Server_Sandbox() )->server_sandbox( $url, $headers, $body, $method ); + ini_set( 'error_log', '/dev/null' ); + try { + ( new Server_Sandbox() )->server_sandbox( $url, $headers, $body, $method ); + } finally { + ini_restore( 'error_log' ); + } $this->assertSame( $expected_url, $url ); diff --git a/projects/packages/forms/changelog/fix-unnecessary-test-outputs b/projects/packages/forms/changelog/fix-unnecessary-test-outputs new file mode 100644 index 0000000000000..7296e96fd8e33 --- /dev/null +++ b/projects/packages/forms/changelog/fix-unnecessary-test-outputs @@ -0,0 +1,5 @@ +Significance: patch +Type: fixed +Comment: Avoid actually trying to send mail during tests. No change to the package itself. + + diff --git a/projects/packages/forms/tests/php/contact-form/test-class.contact-form.php b/projects/packages/forms/tests/php/contact-form/test-class.contact-form.php index 5a6c04c118be1..e9a73f5e0bf45 100644 --- a/projects/packages/forms/tests/php/contact-form/test-class.contact-form.php +++ b/projects/packages/forms/tests/php/contact-form/test-class.contact-form.php @@ -66,6 +66,9 @@ private function set_globals() { * @before */ public function set_up_test_case() { + // Avoid actually trying to send any mail. + add_filter( 'pre_wp_mail', '__return_true', PHP_INT_MAX ); + $this->set_globals(); $author_id = wp_insert_user( diff --git a/projects/plugins/jetpack/changelog/fix-unnecessary-test-outputs b/projects/plugins/jetpack/changelog/fix-unnecessary-test-outputs new file mode 100644 index 0000000000000..ff4b89dbf2cc6 --- /dev/null +++ b/projects/plugins/jetpack/changelog/fix-unnecessary-test-outputs @@ -0,0 +1,5 @@ +Significance: patch +Type: other +Comment: Expect output in `WP_Test_Jetpack_Sync_Sender` test instead of letting it go to the console. No change to the plugin itself. + + diff --git a/projects/plugins/jetpack/tests/php/sync/test_class.jetpack-sync-sender.php b/projects/plugins/jetpack/tests/php/sync/test_class.jetpack-sync-sender.php index fda6ba56e96a4..b0ffc28554b2b 100644 --- a/projects/plugins/jetpack/tests/php/sync/test_class.jetpack-sync-sender.php +++ b/projects/plugins/jetpack/tests/php/sync/test_class.jetpack-sync-sender.php @@ -682,6 +682,7 @@ public function test_do_sync_will_not_spawn_dedicated_sync_request_with_locked_q */ public function test_do_dedicated_sync_and_exit_will_not_re_spawn_dedicated_sync_request_with_empty_queue() { $this->expectException( ExitException::class ); + $this->expectOutputString( Dedicated_Sender::DEDICATED_SYNC_VALIDATION_STRING ); Settings::update_settings( array( 'dedicated_sync_enabled' => 1 ) ); self::factory()->post->create(); @@ -702,6 +703,7 @@ public function test_do_dedicated_sync_and_exit_will_not_re_spawn_dedicated_sync */ public function test_do_dedicated_sync_and_exit_will_not_re_spawn_dedicated_sync_request_with_locked_queue() { $this->expectException( ExitException::class ); + $this->expectOutputString( Dedicated_Sender::DEDICATED_SYNC_VALIDATION_STRING ); Settings::update_settings( array( 'dedicated_sync_enabled' => 1 ) ); $this->sender->get_sync_queue()->lock( 0 ); @@ -723,6 +725,7 @@ public function test_do_dedicated_sync_and_exit_will_not_re_spawn_dedicated_sync */ public function test_do_dedicated_sync_and_exit_will_re_spawn_dedicated_sync_request() { $this->expectException( ExitException::class ); + $this->expectOutputString( Dedicated_Sender::DEDICATED_SYNC_VALIDATION_STRING ); Settings::update_settings( array( 'dedicated_sync_enabled' => 1 ) ); // Process one action at each run.