Skip to content

Commit

Permalink
Clean up output from various tests (Automattic#34256)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
anomiex authored Nov 22, 2023
1 parent ce6f1da commit 040ca55
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: fixed
Comment: Avoid output in test. No change to the package itself.


4 changes: 2 additions & 2 deletions projects/packages/blaze/tests/php/test-blaze.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: fixed
Comment: Avoid `error_log` output in `Test_Server_Sandbox`. No change to the package itself.


2 changes: 1 addition & 1 deletion projects/packages/connection/src/class-package-version.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
class Package_Version {

const PACKAGE_VERSION = '2.0.2';
const PACKAGE_VERSION = '2.0.3-alpha';

const PACKAGE_SLUG = 'connection';

Expand Down
4 changes: 4 additions & 0 deletions projects/packages/connection/tests/.phpcs.dir.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0"?>
<ruleset>
<rule ref="Jetpack-Tests" />
</ruleset>
14 changes: 12 additions & 2 deletions projects/packages/connection/tests/php/test_Server_Sandbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: fixed
Comment: Avoid actually trying to send mail during tests. No change to the package itself.


Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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.


Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 );
Expand All @@ -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.
Expand Down

0 comments on commit 040ca55

Please sign in to comment.