Skip to content

Commit

Permalink
fixed phpunit 8/9 compat
Browse files Browse the repository at this point in the history
  • Loading branch information
nosilver4u committed Mar 24, 2023
1 parent 53d28b7 commit 2390a48
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ services:

env:
- WP_VERSION=latest WP_MULTISITE=0
- WP_VERSION=5.8 WP_MULTISITE=0
- WP_VERSION=5.9 WP_MULTISITE=0

jobs:
include:
Expand Down
11 changes: 11 additions & 0 deletions common.php
Original file line number Diff line number Diff line change
Expand Up @@ -14751,6 +14751,17 @@ function ewwwio_debug_message( $message ) {
if ( ! is_string( $message ) && ! is_int( $message ) && ! is_float( $message ) ) {
return;
}
if ( defined( 'EIO_PHPUNIT' ) && EIO_PHPUNIT ) {
if (
! empty( $_SERVER['argv'] ) &&
( in_array( '--debug', $_SERVER['argv'], true ) || in_array( '--verbose', $_SERVER['argv'], true ) )
) {
$message = str_replace( '<br>', "\n", $message );
$message = str_replace( '<b>', '+', $message );
$message = str_replace( '</b>', '+', $message );
echo esc_html( $message ) . "\n";
}
}
$message = "$message";
if ( defined( 'WP_CLI' ) && WP_CLI ) {
WP_CLI::debug( $message );
Expand Down
6 changes: 6 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,11 @@ function _manually_load_plugin() {
define( 'EIO_PHPUNIT', true );
}

if ( ! empty( $_SERVER['HOME'] ) ) {
if ( is_file( $_SERVER['HOME'] . '/Documents/GitHub/PHPUnit-Polyfills/phpunitpolyfills-autoload.php' ) ) {
require( $_SERVER['HOME'] . '/Documents/GitHub/PHPUnit-Polyfills/phpunitpolyfills-autoload.php' );
}
}

// Start up the WP testing environment.
require $_tests_dir . '/includes/bootstrap.php';
2 changes: 1 addition & 1 deletion tests/test-agr.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function tear_down() {
delete_option( 'ewww_image_optimizer_cloud_key' );
delete_site_option( 'ewww_image_optimizer_version' );
delete_site_option( 'ewww_image_optimizer_cloud_key' );
parent::tearDown();
parent::tear_down();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/test-convert.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ function tear_down() {
delete_option( 'ewww_image_optimizer_cloud_key' );
delete_site_option( 'ewww_image_optimizer_version' );
delete_site_option( 'ewww_image_optimizer_cloud_key' );
parent::tearDown();
parent::tear_down();
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/test-optimize.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public static function set_up_before_class() {
* Initializes the plugin and installs the ewwwio_images table.
*/
function set_up() {
parent::setUp();
parent::set_up();
remove_filter( 'query', array( $this, '_create_temporary_tables' ) );
ewww_image_optimizer_install_table();
add_filter( 'query', array( $this, '_create_temporary_tables' ) );
Expand Down Expand Up @@ -380,7 +380,7 @@ function test_optimize_png_40_optipng() {
update_site_option( 'ewww_image_optimizer_optipng_level', 2 );
update_site_option( 'ewww_image_optimizer_metadata_remove', true );
$results = $this->optimize_png();
$this->assertEquals( 38603, filesize( $results[0] ) );
$this->assertLessThanOrEqual( 39000, filesize( $results[0] ) );
unlink( $results[0] );
}

Expand Down Expand Up @@ -563,7 +563,7 @@ function tear_down() {
delete_option( 'ewww_image_optimizer_cloud_key' );
delete_site_option( 'ewww_image_optimizer_version' );
delete_site_option( 'ewww_image_optimizer_cloud_key' );
parent::tearDown();
parent::tear_down();
}

/**
Expand Down
17 changes: 16 additions & 1 deletion tests/test-resize.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static function set_up_before_class() {
* Initializes the plugin and installs the ewwwio_images table.
*/
function set_up() {
parent::setUp();
parent::set_up();
remove_filter( 'query', array( $this, '_create_temporary_tables' ) );
ewww_image_optimizer_install_table();
add_filter( 'query', array( $this, '_create_temporary_tables' ) );
Expand Down Expand Up @@ -132,6 +132,21 @@ function test_crop_jpg_cloud() {
$this->assertEquals( 1024, $height );
}

/**
* Cleans up ewwwio_images table.
*/
function tear_down() {
global $wpdb;
remove_filter( 'query', array( $this, '_drop_temporary_tables' ) );
$wpdb->query( "DROP TABLE IF EXISTS $wpdb->ewwwio_images" );
add_filter( 'query', array( $this, '_drop_temporary_tables' ) );
delete_option( 'ewww_image_optimizer_version' );
delete_option( 'ewww_image_optimizer_cloud_key' );
delete_site_option( 'ewww_image_optimizer_version' );
delete_site_option( 'ewww_image_optimizer_cloud_key' );
parent::tear_down();
}

/**
* Cleans up the temp images.
*/
Expand Down
4 changes: 2 additions & 2 deletions tests/test-tables.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static function set_up_before_class() {
* Initializes the plugin and installs the ewwwio_images table.
*/
function set_up() {
parent::setUp();
parent::set_up();
remove_filter( 'query', array( $this, '_create_temporary_tables' ) );
ewww_image_optimizer_install_table();
add_filter( 'query', array( $this, '_create_temporary_tables' ) );
Expand Down Expand Up @@ -117,7 +117,7 @@ function tear_down() {
add_filter( 'query', array( $this, '_drop_temporary_tables' ) );
delete_option( 'ewww_image_optimizer_version' );
delete_site_option( 'ewww_image_optimizer_version' );
parent::tearDown();
parent::tear_down();
}

/**
Expand Down

0 comments on commit 2390a48

Please sign in to comment.