diff --git a/.travis.yml b/.travis.yml index 62c8d84542..7725c722d5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,7 +15,7 @@ matrix: - php: 7.2 env: WP_TRAVISCI=e2e - php: 7.2 - env: WP_TRAVISCI=travis:format + env: WP_TRAVISCI=travis:phpcs - php: 7.1 env: WP_TRAVISCI=travis:js - php: 7.4snapshot @@ -83,8 +83,8 @@ before_script: esac fi - | - # We only need to run composer install on the code formatting job. - if [[ "$WP_TRAVISCI" == "travis:format" ]]; then + # We only need to run composer install on the PHP coding standards job. + if [[ "$WP_TRAVISCI" == "travis:phpcs" ]]; then composer --version travis_retry composer install fi diff --git a/Gruntfile.js b/Gruntfile.js index 870e3e1305..815999009f 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1438,10 +1438,31 @@ module.exports = function(grunt) { } ); } ); + grunt.registerTask( 'lint:php', 'Runs the code linter on changed files.', function() { + var done = this.async(); + var flags = this.flags; + var args = changedFiles.php; + if ( flags.travis ) { + args = [ 'tests' ]; + } + args.unshift( 'lint' ); + grunt.util.spawn( { + cmd: 'composer', + args: args, + opts: { stdio: 'inherit' } + }, function( error ) { + if ( flags.error && error ) { + done( false ); + } else { + done( true ); + } + } ); + } ); + // Travis CI tasks. grunt.registerTask('travis:js', 'Runs Javascript Travis CI tasks.', [ 'jshint:corejs', 'qunit:compiled' ]); grunt.registerTask('travis:phpunit', 'Runs PHPUnit Travis CI tasks.', [ 'build', 'phpunit' ]); - grunt.registerTask('travis:format', 'Runs Code formatting Travis CI tasks.', [ 'format:php:error' ]); + grunt.registerTask('travis:phpcs', 'Runs PHP Coding Standards Travis CI tasks.', [ 'format:php:error', 'lint:php:travis:error' ]); // Patch task. grunt.renameTask('patch_wordpress', 'patch'); diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 4cdad01092..cf6244c2ac 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -185,7 +185,39 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/phpunit.xml.dist b/phpunit.xml.dist index faef186978..288e2b0f97 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -43,7 +43,7 @@ - + 150 diff --git a/tests/phpunit/includes/bootstrap.php b/tests/phpunit/includes/bootstrap.php index 461a0b8631..68e8b60792 100644 --- a/tests/phpunit/includes/bootstrap.php +++ b/tests/phpunit/includes/bootstrap.php @@ -76,7 +76,7 @@ $GLOBALS['PHP_SELF'] = '/index.php'; $_SERVER['PHP_SELF'] = '/index.php'; // Should we run in multisite mode? -$multisite = '1' == getenv( 'WP_MULTISITE' ); +$multisite = ( '1' === getenv( 'WP_MULTISITE' ) ); $multisite = $multisite || ( defined( 'WP_TESTS_MULTISITE' ) && WP_TESTS_MULTISITE ); $multisite = $multisite || ( defined( 'MULTISITE' ) && MULTISITE ); @@ -191,7 +191,7 @@ class WP_PHPUnit_Util_Getopt { } foreach ( $skipped_groups as $group_name => $skipped ) { - if ( in_array( $group_name, $groups ) ) { + if ( in_array( $group_name, $groups, true ) ) { $skipped_groups[ $group_name ] = false; } } diff --git a/tests/phpunit/includes/functions.php b/tests/phpunit/includes/functions.php index 002e2ea3e6..d21aa25235 100644 --- a/tests/phpunit/includes/functions.php +++ b/tests/phpunit/includes/functions.php @@ -100,6 +100,7 @@ function _delete_all_data() { $wpdb->term_relationships, $wpdb->termmeta, ) as $table ) { + //phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared $wpdb->query( "DELETE FROM {$table}" ); } @@ -107,6 +108,7 @@ function _delete_all_data() { $wpdb->terms, $wpdb->term_taxonomy, ) as $table ) { + //phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared $wpdb->query( "DELETE FROM {$table} WHERE term_id != 1" ); } diff --git a/tests/phpunit/includes/install.php b/tests/phpunit/includes/install.php index 9400b6966c..d07079e501 100644 --- a/tests/phpunit/includes/install.php +++ b/tests/phpunit/includes/install.php @@ -53,10 +53,12 @@ echo 'Installing...' . PHP_EOL; $wpdb->query( 'SET foreign_key_checks = 0' ); foreach ( $wpdb->tables() as $table => $prefixed_table ) { + //phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared $wpdb->query( "DROP TABLE IF EXISTS $prefixed_table" ); } foreach ( $wpdb->tables( 'ms_global' ) as $table => $prefixed_table ) { + //phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared $wpdb->query( "DROP TABLE IF EXISTS $prefixed_table" ); // We need to create references to ms global tables. diff --git a/tests/phpunit/includes/mock-fs.php b/tests/phpunit/includes/mock-fs.php index b0b24d1a24..8794c07257 100644 --- a/tests/phpunit/includes/mock-fs.php +++ b/tests/phpunit/includes/mock-fs.php @@ -61,12 +61,12 @@ class WP_Filesystem_MockFS extends WP_Filesystem_Base { foreach ( $paths as $path ) { // Allow for comments - if ( '#' == $path[0] ) { + if ( '#' === $path[0] ) { continue; } // Directories - if ( '/' == $path[ strlen( $path ) - 1 ] ) { + if ( '/' === $path[ strlen( $path ) - 1 ] ) { $this->mkdir( $path ); } else { // Files (with dummy content for now) $this->put_contents( $path, 'This is a test file' ); @@ -161,7 +161,7 @@ class WP_Filesystem_MockFS extends WP_Filesystem_Base { function dirlist( $path = '.', $include_hidden = true, $recursive = false ) { - if ( empty( $path ) || '.' == $path ) { + if ( empty( $path ) || '.' === $path ) { $path = $this->cwd(); } @@ -177,15 +177,15 @@ class WP_Filesystem_MockFS extends WP_Filesystem_Base { $ret = array(); foreach ( $this->fs_map[ $path ]->children as $entry ) { - if ( '.' == $entry->name || '..' == $entry->name ) { + if ( '.' === $entry->name || '..' === $entry->name ) { continue; } - if ( ! $include_hidden && '.' == $entry->name ) { + if ( ! $include_hidden && '.' === $entry->name ) { continue; } - if ( $limit_file && $entry->name != $limit_file ) { + if ( $limit_file && $entry->name !== $limit_file ) { continue; } @@ -193,7 +193,7 @@ class WP_Filesystem_MockFS extends WP_Filesystem_Base { $struc['name'] = $entry->name; $struc['type'] = $entry->type; - if ( 'd' == $struc['type'] ) { + if ( 'd' === $struc['type'] ) { if ( $recursive ) { $struc['files'] = $this->dirlist( trailingslashit( $path ) . trailingslashit( $struc['name'] ), $include_hidden, $recursive ); } else { @@ -219,11 +219,11 @@ class MockFS_Node { } function is_file() { - return $this->type == 'f'; + return 'f' === $this->type; } function is_dir() { - return $this->type == 'd'; + return 'd' === $this->type; } } diff --git a/tests/phpunit/includes/object-cache.php b/tests/phpunit/includes/object-cache.php index d333310cec..8fcc4f9261 100644 --- a/tests/phpunit/includes/object-cache.php +++ b/tests/phpunit/includes/object-cache.php @@ -872,10 +872,10 @@ class WP_Object_Cache { * @param string $group The group value appended to the $key. * @param int $expiration The expiration time, defaults to 0. * @param string $server_key The key identifying the server to store the value on. - * @param bool $byKey True to store in internal cache by key; false to not store by key + * @param bool $by_key True to store in internal cache by key; false to not store by key * @return bool Returns TRUE on success or FALSE on failure. */ - public function add( $key, $value, $group = 'default', $expiration = 0, $server_key = '', $byKey = false ) { + public function add( $key, $value, $group = 'default', $expiration = 0, $server_key = '', $by_key = false ) { /* * Ensuring that wp_suspend_cache_addition is defined before calling, because sometimes an advanced-cache.php * file will load object-cache.php before wp-includes/functions.php is loaded. In those cases, if wp_cache_add @@ -890,7 +890,7 @@ class WP_Object_Cache { $expiration = $this->sanitize_expiration( $expiration ); // If group is a non-Memcached group, save to runtime cache, not Memcached - if ( in_array( $group, $this->no_mc_groups ) ) { + if ( in_array( $group, $this->no_mc_groups, true ) ) { // Add does not set the value if the key exists; mimic that here if ( isset( $this->cache[ $derived_key ] ) ) { @@ -903,7 +903,7 @@ class WP_Object_Cache { } // Save to Memcached - if ( $byKey ) { + if ( $by_key ) { $result = $this->m->addByKey( $server_key, $derived_key, $value, $expiration ); } else { $result = $this->m->add( $derived_key, $value, $expiration ); @@ -991,10 +991,10 @@ class WP_Object_Cache { * @param mixed $value Must be string as appending mixed values is not well-defined. * @param string $group The group value appended to the $key. * @param string $server_key The key identifying the server to store the value on. - * @param bool $byKey True to store in internal cache by key; false to not store by key + * @param bool $by_key True to store in internal cache by key; false to not store by key * @return bool Returns TRUE on success or FALSE on failure. */ - public function append( $key, $value, $group = 'default', $server_key = '', $byKey = false ) { + public function append( $key, $value, $group = 'default', $server_key = '', $by_key = false ) { if ( ! is_string( $value ) && ! is_int( $value ) && ! is_float( $value ) ) { return false; } @@ -1002,7 +1002,7 @@ class WP_Object_Cache { $derived_key = $this->buildKey( $key, $group ); // If group is a non-Memcached group, append to runtime cache value, not Memcached - if ( in_array( $group, $this->no_mc_groups ) ) { + if ( in_array( $group, $this->no_mc_groups, true ) ) { if ( ! isset( $this->cache[ $derived_key ] ) ) { return false; } @@ -1013,7 +1013,7 @@ class WP_Object_Cache { } // Append to Memcached value - if ( $byKey ) { + if ( $by_key ) { $result = $this->m->appendByKey( $server_key, $derived_key, $value ); } else { $result = $this->m->append( $derived_key, $value ); @@ -1064,10 +1064,10 @@ class WP_Object_Cache { * @param string $group The group value appended to the $key. * @param int $expiration The expiration time, defaults to 0. * @param string $server_key The key identifying the server to store the value on. - * @param bool $byKey True to store in internal cache by key; false to not store by key + * @param bool $by_key True to store in internal cache by key; false to not store by key * @return bool Returns TRUE on success or FALSE on failure. */ - public function cas( $cas_token, $key, $value, $group = 'default', $expiration = 0, $server_key = '', $byKey = false ) { + public function cas( $cas_token, $key, $value, $group = 'default', $expiration = 0, $server_key = '', $by_key = false ) { $derived_key = $this->buildKey( $key, $group ); $expiration = $this->sanitize_expiration( $expiration ); @@ -1076,13 +1076,13 @@ class WP_Object_Cache { * that since check and set cannot be emulated in the run time cache, this value * operation is treated as a normal "add" for no_mc_groups. */ - if ( in_array( $group, $this->no_mc_groups ) ) { + if ( in_array( $group, $this->no_mc_groups, true ) ) { $this->add_to_internal_cache( $derived_key, $value ); return true; } // Save to Memcached - if ( $byKey ) { + if ( $by_key ) { $result = $this->m->casByKey( $cas_token, $server_key, $derived_key, $value, $expiration ); } else { $result = $this->m->cas( $cas_token, $derived_key, $value, $expiration ); @@ -1130,7 +1130,7 @@ class WP_Object_Cache { $derived_key = $this->buildKey( $key, $group ); // Decrement values in no_mc_groups - if ( in_array( $group, $this->no_mc_groups ) ) { + if ( in_array( $group, $this->no_mc_groups, true ) ) { // Only decrement if the key already exists and value is 0 or greater (mimics memcached behavior) if ( isset( $this->cache[ $derived_key ] ) && $this->cache[ $derived_key ] >= 0 ) { @@ -1191,14 +1191,14 @@ class WP_Object_Cache { * @param string $group The group value appended to the $key. * @param int $time The amount of time the server will wait to delete the item in seconds. * @param string $server_key The key identifying the server to store the value on. - * @param bool $byKey True to store in internal cache by key; false to not store by key + * @param bool $by_key True to store in internal cache by key; false to not store by key * @return bool Returns TRUE on success or FALSE on failure. */ - public function delete( $key, $group = 'default', $time = 0, $server_key = '', $byKey = false ) { + public function delete( $key, $group = 'default', $time = 0, $server_key = '', $by_key = false ) { $derived_key = $this->buildKey( $key, $group ); // Remove from no_mc_groups array - if ( in_array( $group, $this->no_mc_groups ) ) { + if ( in_array( $group, $this->no_mc_groups, true ) ) { if ( isset( $this->cache[ $derived_key ] ) ) { unset( $this->cache[ $derived_key ] ); } @@ -1206,7 +1206,7 @@ class WP_Object_Cache { return true; } - if ( $byKey ) { + if ( $by_key ) { $result = $this->m->deleteByKey( $server_key, $derived_key, $time ); } else { $result = $this->m->delete( $derived_key, $time ); @@ -1299,20 +1299,20 @@ class WP_Object_Cache { * @param bool $force Whether or not to force a cache invalidation. * @param null|bool $found Variable passed by reference to determine if the value was found or not. * @param string $server_key The key identifying the server to store the value on. - * @param bool $byKey True to store in internal cache by key; false to not store by key + * @param bool $by_key True to store in internal cache by key; false to not store by key * @param null|callable $cache_cb Read-through caching callback. * @param null|float $cas_token The variable to store the CAS token in. * @return bool|mixed Cached object value. */ - public function get( $key, $group = 'default', $force = false, &$found = null, $server_key = '', $byKey = false, $cache_cb = null, &$cas_token = null ) { + public function get( $key, $group = 'default', $force = false, &$found = null, $server_key = '', $by_key = false, $cache_cb = null, &$cas_token = null ) { $derived_key = $this->buildKey( $key, $group ); // Assume object is not found $found = false; // If either $cache_db, or $cas_token is set, must hit Memcached and bypass runtime cache - if ( func_num_args() > 6 && ! in_array( $group, $this->no_mc_groups ) ) { - if ( $byKey ) { + if ( func_num_args() > 6 && ! in_array( $group, $this->no_mc_groups, true ) ) { + if ( $by_key ) { $value = $this->m->getByKey( $server_key, $derived_key, $cache_cb, $cas_token ); } else { $value = $this->m->get( $derived_key, $cache_cb, $cas_token ); @@ -1321,10 +1321,10 @@ class WP_Object_Cache { if ( isset( $this->cache[ $derived_key ] ) ) { $found = true; return is_object( $this->cache[ $derived_key ] ) ? clone $this->cache[ $derived_key ] : $this->cache[ $derived_key ]; - } elseif ( in_array( $group, $this->no_mc_groups ) ) { + } elseif ( in_array( $group, $this->no_mc_groups, true ) ) { return false; } else { - if ( $byKey ) { + if ( $by_key ) { $value = $this->m->getByKey( $server_key, $derived_key ); } else { $value = $this->m->get( $derived_key ); @@ -1464,7 +1464,7 @@ class WP_Object_Cache { } // If order should be preserved, reorder now - if ( ! empty( $need_to_get ) && $flags === Memcached::GET_PRESERVE_ORDER ) { + if ( ! empty( $need_to_get ) && Memcached::GET_PRESERVE_ORDER === $flags ) { $ordered_values = array(); foreach ( $derived_keys as $key ) { @@ -1603,7 +1603,7 @@ class WP_Object_Cache { $derived_key = $this->buildKey( $key, $group ); // Increment values in no_mc_groups - if ( in_array( $group, $this->no_mc_groups ) ) { + if ( in_array( $group, $this->no_mc_groups, true ) ) { // Only increment if the key already exists and the number is currently 0 or greater (mimics memcached behavior) if ( isset( $this->cache[ $derived_key ] ) && $this->cache[ $derived_key ] >= 0 ) { @@ -1668,10 +1668,10 @@ class WP_Object_Cache { * @param string $value Must be string as prepending mixed values is not well-defined. * @param string $group The group value prepended to the $key. * @param string $server_key The key identifying the server to store the value on. - * @param bool $byKey True to store in internal cache by key; false to not store by key + * @param bool $by_key True to store in internal cache by key; false to not store by key * @return bool Returns TRUE on success or FALSE on failure. */ - public function prepend( $key, $value, $group = 'default', $server_key = '', $byKey = false ) { + public function prepend( $key, $value, $group = 'default', $server_key = '', $by_key = false ) { if ( ! is_string( $value ) && ! is_int( $value ) && ! is_float( $value ) ) { return false; } @@ -1679,7 +1679,7 @@ class WP_Object_Cache { $derived_key = $this->buildKey( $key, $group ); // If group is a non-Memcached group, prepend to runtime cache value, not Memcached - if ( in_array( $group, $this->no_mc_groups ) ) { + if ( in_array( $group, $this->no_mc_groups, true ) ) { if ( ! isset( $this->cache[ $derived_key ] ) ) { return false; } @@ -1690,7 +1690,7 @@ class WP_Object_Cache { } // Append to Memcached value - if ( $byKey ) { + if ( $by_key ) { $result = $this->m->prependByKey( $server_key, $derived_key, $value ); } else { $result = $this->m->prepend( $derived_key, $value ); @@ -1740,16 +1740,16 @@ class WP_Object_Cache { * @param string $key The key under which to store the value. * @param mixed $value The value to store. * @param string $group The group value appended to the $key. - * @param bool $byKey True to store in internal cache by key; false to not store by key + * @param bool $by_key True to store in internal cache by key; false to not store by key * @param int $expiration The expiration time, defaults to 0. * @return bool Returns TRUE on success or FALSE on failure. */ - public function replace( $key, $value, $group = 'default', $expiration = 0, $server_key = '', $byKey = false ) { + public function replace( $key, $value, $group = 'default', $expiration = 0, $server_key = '', $by_key = false ) { $derived_key = $this->buildKey( $key, $group ); $expiration = $this->sanitize_expiration( $expiration ); // If group is a non-Memcached group, save to runtime cache, not Memcached - if ( in_array( $group, $this->no_mc_groups ) ) { + if ( in_array( $group, $this->no_mc_groups, true ) ) { // Replace won't save unless the key already exists; mimic this behavior here if ( ! isset( $this->cache[ $derived_key ] ) ) { @@ -1761,7 +1761,7 @@ class WP_Object_Cache { } // Save to Memcached - if ( $byKey ) { + if ( $by_key ) { $result = $this->m->replaceByKey( $server_key, $derived_key, $value, $expiration ); } else { $result = $this->m->replace( $derived_key, $value, $expiration ); @@ -1806,21 +1806,21 @@ class WP_Object_Cache { * @param string $group The group value appended to the $key. * @param int $expiration The expiration time, defaults to 0. * @param string $server_key The key identifying the server to store the value on. - * @param bool $byKey True to store in internal cache by key; false to not store by key + * @param bool $by_key True to store in internal cache by key; false to not store by key * @return bool Returns TRUE on success or FALSE on failure. */ - public function set( $key, $value, $group = 'default', $expiration = 0, $server_key = '', $byKey = false ) { + public function set( $key, $value, $group = 'default', $expiration = 0, $server_key = '', $by_key = false ) { $derived_key = $this->buildKey( $key, $group ); $expiration = $this->sanitize_expiration( $expiration ); // If group is a non-Memcached group, save to runtime cache, not Memcached - if ( in_array( $group, $this->no_mc_groups ) ) { + if ( in_array( $group, $this->no_mc_groups, true ) ) { $this->add_to_internal_cache( $derived_key, $value ); return true; } // Save to Memcached - if ( $byKey ) { + if ( $by_key ) { $result = $this->m->setByKey( $server_key, $derived_key, $value, $expiration ); } else { $result = $this->m->set( $derived_key, $value, $expiration ); @@ -1867,10 +1867,10 @@ class WP_Object_Cache { * @param string|array $groups Group(s) to merge with key(s) in $items. * @param int $expiration The expiration time, defaults to 0. * @param string $server_key The key identifying the server to store the value on. - * @param bool $byKey True to store in internal cache by key; false to not store by key + * @param bool $by_key True to store in internal cache by key; false to not store by key * @return bool Returns TRUE on success or FALSE on failure. */ - public function setMulti( $items, $groups = 'default', $expiration = 0, $server_key = '', $byKey = false ) { + public function setMulti( $items, $groups = 'default', $expiration = 0, $server_key = '', $by_key = false ) { // Build final keys and replace $items keys with the new keys $derived_keys = $this->buildKeys( array_keys( $items ), $groups ); $expiration = $this->sanitize_expiration( $expiration ); @@ -1883,14 +1883,14 @@ class WP_Object_Cache { $key_pieces = explode( ':', $derived_key ); // If group is a non-Memcached group, save to runtime cache, not Memcached - if ( in_array( $key_pieces[1], $this->no_mc_groups ) ) { + if ( in_array( $key_pieces[1], $this->no_mc_groups, true ) ) { $this->add_to_internal_cache( $derived_key, $value ); unset( $derived_items[ $derived_key ] ); } } // Save to memcached - if ( $byKey ) { + if ( $by_key ) { $result = $this->m->setMultiByKey( $server_key, $derived_items, $expiration ); } else { $result = $this->m->setMulti( $derived_items, $expiration ); @@ -1953,7 +1953,7 @@ class WP_Object_Cache { $group = 'default'; } - if ( false !== array_search( $group, $this->global_groups ) ) { + if ( false !== array_search( $group, $this->global_groups, true ) ) { $prefix = $this->global_prefix; } else { $prefix = $this->blog_prefix; @@ -1991,7 +1991,7 @@ class WP_Object_Cache { } // If we have equal numbers of keys and groups, merge $keys[n] and $group[n] - if ( count( $keys ) == count( $groups ) ) { + if ( count( $keys ) === count( $groups ) ) { for ( $i = 0; $i < count( $keys ); $i++ ) { $derived_keys[] = $this->buildKey( $keys[ $i ], $groups[ $i ] ); } @@ -2001,7 +2001,7 @@ class WP_Object_Cache { for ( $i = 0; $i < count( $keys ); $i++ ) { if ( isset( $groups[ $i ] ) ) { $derived_keys[] = $this->buildKey( $keys[ $i ], $groups[ $i ] ); - } elseif ( count( $groups ) == 1 ) { + } elseif ( count( $groups ) === 1 ) { $derived_keys[] = $this->buildKey( $keys[ $i ], $groups[0] ); } else { $derived_keys[] = $this->buildKey( $keys[ $i ], 'default' ); @@ -2046,7 +2046,7 @@ class WP_Object_Cache { $type = gettype( $original ); // Combine the values based on direction of the "pend" - if ( 'pre' == $direction ) { + if ( 'pre' === $direction ) { $combined = $pended . $original; } else { $combined = $original . $pended; @@ -2080,7 +2080,7 @@ class WP_Object_Cache { */ public function contains_no_mc_group( $groups ) { if ( is_scalar( $groups ) ) { - return in_array( $groups, $this->no_mc_groups ); + return in_array( $groups, $this->no_mc_groups, true ); } if ( ! is_array( $groups ) ) { @@ -2088,7 +2088,7 @@ class WP_Object_Cache { } foreach ( $groups as $group ) { - if ( in_array( $group, $this->no_mc_groups ) ) { + if ( in_array( $group, $this->no_mc_groups, true ) ) { return true; } } diff --git a/tests/phpunit/includes/phpunit6/compat.php b/tests/phpunit/includes/phpunit6/compat.php index 90b53a1bec..de9b0bccac 100644 --- a/tests/phpunit/includes/phpunit6/compat.php +++ b/tests/phpunit/includes/phpunit6/compat.php @@ -18,8 +18,8 @@ if ( class_exists( 'PHPUnit\Runner\Version' ) && version_compare( PHPUnit\Runner class PHPUnit_Util_Test { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid - public static function getTickets( $className, $methodName ) { - $annotations = PHPUnit\Util\Test::parseTestMethodAnnotations( $className, $methodName ); + public static function getTickets( $class_name, $method_name ) { + $annotations = PHPUnit\Util\Test::parseTestMethodAnnotations( $class_name, $method_name ); $tickets = array(); diff --git a/tests/phpunit/includes/phpunit7/speed-trap-listener.php b/tests/phpunit/includes/phpunit7/speed-trap-listener.php index 1d8e995e52..c27fbc21cd 100644 --- a/tests/phpunit/includes/phpunit7/speed-trap-listener.php +++ b/tests/phpunit/includes/phpunit7/speed-trap-listener.php @@ -22,14 +22,14 @@ class SpeedTrapListener implements PHPUnit_Framework_TestListener { * * @var int */ - protected $slowThreshold; + protected $slow_threshold; /** * Number of tests to report on for slowness. * * @var int */ - protected $reportLength; + protected $report_length; /** * Collection of slow tests. @@ -166,11 +166,11 @@ class SpeedTrapListener implements PHPUnit_Framework_TestListener { * Whether the given test execution time is considered slow. * * @param int $time Test execution time in milliseconds - * @param int $slowThreshold Test execution time at which a test should be considered slow (milliseconds) + * @param int $slow_threshold Test execution time at which a test should be considered slow (milliseconds) * @return bool */ - protected function isSlow( $time, $slowThreshold ) { - return $time >= $slowThreshold; + protected function isSlow( $time, $slow_threshold ) { + return $time >= $slow_threshold; } /** @@ -220,7 +220,7 @@ class SpeedTrapListener implements PHPUnit_Framework_TestListener { * @return int */ protected function getReportLength() { - return min( count( $this->slow ), $this->reportLength ); + return min( count( $this->slow ), $this->report_length ); } /** @@ -244,19 +244,19 @@ class SpeedTrapListener implements PHPUnit_Framework_TestListener { * Renders slow test report header. */ protected function renderHeader() { - echo sprintf( "\n\nYou should really fix these slow tests (>%sms)...\n", $this->slowThreshold ); + echo sprintf( "\n\nYou should really fix these slow tests (>%sms)...\n", $this->slow_threshold ); } /** * Renders slow test report body. */ protected function renderBody() { - $slowTests = $this->slow; + $slow_tests = $this->slow; - $length = $this->getReportLength( $slowTests ); + $length = $this->getReportLength( $slow_tests ); for ( $i = 1; $i <= $length; ++$i ) { - $label = key( $slowTests ); - $time = array_shift( $slowTests ); + $label = key( $slow_tests ); + $time = array_shift( $slow_tests ); echo sprintf( " %s. %sms to run %s\n", $i, $time, $label ); } @@ -268,7 +268,7 @@ class SpeedTrapListener implements PHPUnit_Framework_TestListener { protected function renderFooter() { $hidden = $this->getHiddenCount( $this->slow ); if ( $hidden ) { - echo sprintf( '...and there %s %s more above your threshold hidden from view', $hidden == 1 ? 'is' : 'are', $hidden ); + echo sprintf( '...and there %s %s more above your threshold hidden from view', 1 === $hidden ? 'is' : 'are', $hidden ); } } @@ -278,8 +278,8 @@ class SpeedTrapListener implements PHPUnit_Framework_TestListener { * @param array $options */ protected function loadOptions( array $options ) { - $this->slowThreshold = isset( $options['slowThreshold'] ) ? $options['slowThreshold'] : 500; - $this->reportLength = isset( $options['reportLength'] ) ? $options['reportLength'] : 10; + $this->slow_threshold = isset( $options['slowThreshold'] ) ? $options['slowThreshold'] : 500; + $this->report_length = isset( $options['reportLength'] ) ? $options['reportLength'] : 10; } /** @@ -302,6 +302,6 @@ class SpeedTrapListener implements PHPUnit_Framework_TestListener { protected function getSlowThreshold( PHPUnit_Framework_TestCase $test ) { $ann = $test->getAnnotations(); - return isset( $ann['method']['slowThreshold'][0] ) ? $ann['method']['slowThreshold'][0] : $this->slowThreshold; + return isset( $ann['method']['slowThreshold'][0] ) ? $ann['method']['slowThreshold'][0] : $this->slow_threshold; } } diff --git a/tests/phpunit/includes/speed-trap-listener.php b/tests/phpunit/includes/speed-trap-listener.php index eaf738a25e..0de9d9ae86 100644 --- a/tests/phpunit/includes/speed-trap-listener.php +++ b/tests/phpunit/includes/speed-trap-listener.php @@ -22,14 +22,14 @@ class SpeedTrapListener implements PHPUnit_Framework_TestListener { * * @var int */ - protected $slowThreshold; + protected $slow_threshold; /** * Number of tests to report on for slowness. * * @var int */ - protected $reportLength; + protected $report_length; /** * Collection of slow tests. @@ -166,11 +166,11 @@ class SpeedTrapListener implements PHPUnit_Framework_TestListener { * Whether the given test execution time is considered slow. * * @param int $time Test execution time in milliseconds - * @param int $slowThreshold Test execution time at which a test should be considered slow (milliseconds) + * @param int $slow_threshold Test execution time at which a test should be considered slow (milliseconds) * @return bool */ - protected function isSlow( $time, $slowThreshold ) { - return $time >= $slowThreshold; + protected function isSlow( $time, $slow_threshold ) { + return $time >= $slow_threshold; } /** @@ -220,7 +220,7 @@ class SpeedTrapListener implements PHPUnit_Framework_TestListener { * @return int */ protected function getReportLength() { - return min( count( $this->slow ), $this->reportLength ); + return min( count( $this->slow ), $this->report_length ); } /** @@ -244,19 +244,19 @@ class SpeedTrapListener implements PHPUnit_Framework_TestListener { * Renders slow test report header. */ protected function renderHeader() { - echo sprintf( "\n\nYou should really fix these slow tests (>%sms)...\n", $this->slowThreshold ); + echo sprintf( "\n\nYou should really fix these slow tests (>%sms)...\n", $this->slow_threshold ); } /** * Renders slow test report body. */ protected function renderBody() { - $slowTests = $this->slow; + $slow_tests = $this->slow; - $length = $this->getReportLength( $slowTests ); + $length = $this->getReportLength( $slow_tests ); for ( $i = 1; $i <= $length; ++$i ) { - $label = key( $slowTests ); - $time = array_shift( $slowTests ); + $label = key( $slow_tests ); + $time = array_shift( $slow_tests ); echo sprintf( " %s. %sms to run %s\n", $i, $time, $label ); } @@ -267,7 +267,7 @@ class SpeedTrapListener implements PHPUnit_Framework_TestListener { */ protected function renderFooter() { if ( $hidden = $this->getHiddenCount( $this->slow ) ) { - echo sprintf( '...and there %s %s more above your threshold hidden from view', $hidden == 1 ? 'is' : 'are', $hidden ); + echo sprintf( '...and there %s %s more above your threshold hidden from view', 1 === $hidden ? 'is' : 'are', $hidden ); } } @@ -277,8 +277,8 @@ class SpeedTrapListener implements PHPUnit_Framework_TestListener { * @param array $options */ protected function loadOptions( array $options ) { - $this->slowThreshold = isset( $options['slowThreshold'] ) ? $options['slowThreshold'] : 500; - $this->reportLength = isset( $options['reportLength'] ) ? $options['reportLength'] : 10; + $this->slow_threshold = isset( $options['slowThreshold'] ) ? $options['slowThreshold'] : 500; + $this->report_length = isset( $options['reportLength'] ) ? $options['reportLength'] : 10; } /** @@ -301,6 +301,6 @@ class SpeedTrapListener implements PHPUnit_Framework_TestListener { protected function getSlowThreshold( PHPUnit_Framework_TestCase $test ) { $ann = $test->getAnnotations(); - return isset( $ann['method']['slowThreshold'][0] ) ? $ann['method']['slowThreshold'][0] : $this->slowThreshold; + return isset( $ann['method']['slowThreshold'][0] ) ? $ann['method']['slowThreshold'][0] : $this->slow_threshold; } } diff --git a/tests/phpunit/includes/trac.php b/tests/phpunit/includes/trac.php index 6e9a69f36f..dd3783e7be 100644 --- a/tests/phpunit/includes/trac.php +++ b/tests/phpunit/includes/trac.php @@ -41,7 +41,7 @@ class TracTickets { self::$trac_ticket_cache[ $trac_url ] = $tickets; } - return ! in_array( $ticket_id, self::$trac_ticket_cache[ $trac_url ] ); + return ! in_array( $ticket_id, self::$trac_ticket_cache[ $trac_url ], true ); } // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid diff --git a/tests/phpunit/includes/utils.php b/tests/phpunit/includes/utils.php index 06d762f773..f2131ac23f 100644 --- a/tests/phpunit/includes/utils.php +++ b/tests/phpunit/includes/utils.php @@ -152,7 +152,7 @@ class MockAction { if ( $tag ) { $count = 0; foreach ( $this->events as $e ) { - if ( $e['action'] == $tag ) { + if ( $e['action'] === $tag ) { ++$count; } } @@ -222,8 +222,12 @@ class TestXMLParser { } function data_handler( $parser, $data ) { - $index = count( $this->data ) - 1; - @$this->data[ $index ]['content'] .= $data; + $index = count( $this->data ) - 1; + + if ( ! isset( $this->data[ $index ]['content'] ) ) { + $this->data[ $index ]['content'] = ''; + } + $this->data[ $index ]['content'] .= $data; } function end_handler( $parser, $name ) { @@ -253,9 +257,9 @@ function xml_find( $tree /*, $el1, $el2, $el3, .. */ ) { for ( $i = 0; $i < count( $tree ); $i++ ) { # echo "checking '{$tree[$i][name]}' == '{$a[0]}'\n"; # var_dump($tree[$i]['name'], $a[0]); - if ( $tree[ $i ]['name'] == $a[0] ) { + if ( $tree[ $i ]['name'] === $a[0] ) { # echo "n == {$n}\n"; - if ( $n == 1 ) { + if ( 1 === $n ) { $out[] = $tree[ $i ]; } else { $subtree =& $tree[ $i ]['child']; @@ -348,6 +352,7 @@ function drop_tables() { global $wpdb; $tables = $wpdb->get_col( 'SHOW TABLES;' ); foreach ( $tables as $table ) { + // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared $wpdb->query( "DROP TABLE IF EXISTS {$table}" ); } } @@ -438,7 +443,7 @@ function _clean_term_filters() { /** * Special class for exposing protected wpdb methods we need to access */ -class wpdb_exposed_methods_for_testing extends wpdb { +class WpdbExposedMethodsForTesting extends wpdb { public function __construct() { global $wpdb; $this->dbh = $wpdb->dbh; diff --git a/tests/phpunit/includes/wp-profiler.php b/tests/phpunit/includes/wp-profiler.php index 557cfb27ff..60628d2917 100644 --- a/tests/phpunit/includes/wp-profiler.php +++ b/tests/phpunit/includes/wp-profiler.php @@ -114,10 +114,10 @@ class WPProfiler { public function log_filter( $tag ) { if ( $this->stack ) { global $wp_actions; - if ( $tag == end( $wp_actions ) ) { - @$this->stack[ count( $this->stack ) - 1 ]['actions'][ $tag ] ++; + if ( end( $wp_actions ) === $tag ) { + $this->stack[ count( $this->stack ) - 1 ]['actions'][ $tag ]++; } else { - @$this->stack[ count( $this->stack ) - 1 ]['filters'][ $tag ] ++; + $this->stack[ count( $this->stack ) - 1 ]['filters'][ $tag ]++; } } return $arg; @@ -125,7 +125,7 @@ class WPProfiler { public function log_action( $tag ) { if ( $this->stack ) { - @$this->stack[ count( $this->stack ) - 1 ]['actions'][ $tag ] ++; + $this->stack[ count( $this->stack ) - 1 ]['actions'][ $tag ]++; } } @@ -144,7 +144,7 @@ class WPProfiler { $sql = preg_replace( '/(WHERE \w+ =) \d+/', '$1 x', $sql ); $sql = preg_replace( '/(WHERE \w+ =) \'\[-\w]+\'/', '$1 \'xxx\'', $sql ); - @$out[ $sql ] ++; + $out[ $sql ] ++; } asort( $out ); return; @@ -155,9 +155,9 @@ class WPProfiler { $out = array(); foreach ( $queries as $q ) { if ( empty( $q[2] ) ) { - @$out['unknown'] ++; + $out['unknown']++; } else { - @$out[ $q[2] ] ++; + $out[ $q[2] ]++; } } return $out; diff --git a/tests/phpunit/tests/admin/includesPlugin.php b/tests/phpunit/tests/admin/includesPlugin.php index 174e6e9a4c..916ca755b7 100644 --- a/tests/phpunit/tests/admin/includesPlugin.php +++ b/tests/phpunit/tests/admin/includesPlugin.php @@ -102,8 +102,8 @@ class Tests_Admin_includesPlugin extends WP_UnitTestCase { $plugin = $this->_create_plugin( null, 'list_files_test_plugin.php', $plugin_dir ); $sub_dir = trailingslashit( dirname( $plugin[1] ) ) . 'subdir'; - @mkdir( $sub_dir ); - @file_put_contents( $sub_dir . '/subfile.php', 'get_charset_collate(); $max_index_length = 191; + // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared $wpdb->query( " CREATE TABLE {$options} ( @@ -66,6 +67,7 @@ class Tests_Admin_Includes_Schema extends WP_UnitTestCase { ) {$charset_collate} " ); + // phpcs:enable } /** @@ -78,9 +80,11 @@ class Tests_Admin_Includes_Schema extends WP_UnitTestCase { $blogmeta = self::$blogmeta; $sitemeta = self::$sitemeta; + // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared $wpdb->query( "DROP TABLE IF EXISTS {$options}" ); $wpdb->query( "DROP TABLE IF EXISTS {$blogmeta}" ); $wpdb->query( "DROP TABLE IF EXISTS {$sitemeta}" ); + // phpcs:enable } /** diff --git a/tests/phpunit/tests/adminbar.php b/tests/phpunit/tests/adminbar.php index cc42321bc2..a9a2ed4564 100644 --- a/tests/phpunit/tests/adminbar.php +++ b/tests/phpunit/tests/adminbar.php @@ -744,7 +744,7 @@ class Tests_AdminBar extends WP_UnitTestCase { $nodes = $wp_admin_bar->get_nodes(); foreach ( $this->get_my_sites_network_menu_items() as $id => $cap ) { - if ( in_array( $cap, $network_user_caps ) ) { + if ( in_array( $cap, $network_user_caps, true ) ) { $this->assertTrue( isset( $nodes[ $id ] ), sprintf( 'Menu item %1$s must display for a user with the %2$s cap.', $id, $cap ) ); } else { $this->assertFalse( isset( $nodes[ $id ] ), sprintf( 'Menu item %1$s must not display for a user without the %2$s cap.', $id, $cap ) ); diff --git a/tests/phpunit/tests/ajax/CustomizeMenus.php b/tests/phpunit/tests/ajax/CustomizeMenus.php index ca9ce84cc8..bca0bdcc64 100644 --- a/tests/phpunit/tests/ajax/CustomizeMenus.php +++ b/tests/phpunit/tests/ajax/CustomizeMenus.php @@ -52,7 +52,7 @@ class Tests_Ajax_CustomizeMenus extends WP_Ajax_UnitTestCase { */ function test_ajax_load_available_items_cap_check( $role, $expected_results ) { - if ( 'administrator' != $role ) { + if ( 'administrator' !== $role ) { // If we're not an admin, we should get a wp_die(-1). $this->setExpectedException( 'WPAjaxDieStopException' ); } @@ -441,7 +441,7 @@ class Tests_Ajax_CustomizeMenus extends WP_Ajax_UnitTestCase { */ function test_ajax_search_available_items_caps_check( $role, $expected_results ) { - if ( 'administrator' != $role ) { + if ( 'administrator' !== $role ) { // If we're not an admin, we should get a wp_die(-1). $this->setExpectedException( 'WPAjaxDieStopException' ); } diff --git a/tests/phpunit/tests/ajax/DeleteComment.php b/tests/phpunit/tests/ajax/DeleteComment.php index 2da5228f71..6664b662ab 100644 --- a/tests/phpunit/tests/ajax/DeleteComment.php +++ b/tests/phpunit/tests/ajax/DeleteComment.php @@ -94,11 +94,11 @@ class Tests_Ajax_DeleteComment extends WP_Ajax_UnitTestCase { $this->assertLessThanOrEqual( time(), (int) $xml->response[0]->comment[0]->supplemental[0]->time[0] ); // trash, spam, delete should make the total go down - if ( in_array( $action, array( 'trash', 'spam', 'delete' ) ) ) { + if ( in_array( $action, array( 'trash', 'spam', 'delete' ), true ) ) { $total = $_POST['_total'] - 1; // unspam, untrash should make the total go up - } elseif ( in_array( $action, array( 'untrash', 'unspam' ) ) ) { + } elseif ( in_array( $action, array( 'untrash', 'unspam' ), true ) ) { $total = $_POST['_total'] + 1; } @@ -108,7 +108,7 @@ class Tests_Ajax_DeleteComment extends WP_Ajax_UnitTestCase { // Check for either possible total $message = sprintf( 'returned value: %1$d $total: %2$d $recalc_total: %3$d', (int) $xml->response[0]->comment[0]->supplemental[0]->total[0], $total, $recalc_total ); - $this->assertTrue( in_array( (int) $xml->response[0]->comment[0]->supplemental[0]->total[0], array( $total, $recalc_total ) ), $message ); + $this->assertTrue( in_array( (int) $xml->response[0]->comment[0]->supplemental[0]->total[0], array( $total, $recalc_total ), true ), $message ); } /** @@ -243,7 +243,7 @@ class Tests_Ajax_DeleteComment extends WP_Ajax_UnitTestCase { $this->_last_response = ''; // Force delete the comment - if ( 'delete' == $action ) { + if ( 'delete' === $action ) { wp_delete_comment( $comment->comment_ID, true ); } diff --git a/tests/phpunit/tests/ajax/DimComment.php b/tests/phpunit/tests/ajax/DimComment.php index 40bb5b207d..a18e3d0e59 100644 --- a/tests/phpunit/tests/ajax/DimComment.php +++ b/tests/phpunit/tests/ajax/DimComment.php @@ -89,7 +89,7 @@ class Tests_Ajax_DimComment extends WP_Ajax_UnitTestCase { // Check the status $current = wp_get_comment_status( $comment->comment_ID ); - if ( in_array( $prev_status, array( 'unapproved', 'spam' ) ) ) { + if ( in_array( $prev_status, array( 'unapproved', 'spam' ), true ) ) { $this->assertEquals( 'approved', $current ); } else { $this->assertEquals( 'unapproved', $current ); @@ -103,7 +103,7 @@ class Tests_Ajax_DimComment extends WP_Ajax_UnitTestCase { $total = $_POST['_total'] - 1; // Check for either possible total - $this->assertTrue( in_array( (int) $xml->response[0]->comment[0]->supplemental[0]->total[0], array( $total, $recalc_total ) ) ); + $this->assertTrue( in_array( (int) $xml->response[0]->comment[0]->supplemental[0]->total[0], array( $total, $recalc_total ), true ) ); } /** diff --git a/tests/phpunit/tests/ajax/EditComment.php b/tests/phpunit/tests/ajax/EditComment.php index b6c5dc0ffe..7fb58eff57 100644 --- a/tests/phpunit/tests/ajax/EditComment.php +++ b/tests/phpunit/tests/ajax/EditComment.php @@ -96,7 +96,7 @@ class Tests_Ajax_EditComment extends WP_Ajax_UnitTestCase { $comment = array_pop( $comments ); // Manually update the comment_post_ID, because wp_update_comment() will prevent it. - $wpdb->query( "UPDATE {$wpdb->comments} SET comment_post_ID=0 WHERE comment_ID={$comment->comment_ID}" ); + $wpdb->update( $wpdb->comments, array( 'comment_post_ID' => 0 ), array( 'comment_ID' => $comment->comment_ID ) ); clean_comment_cache( $comment->comment_ID ); // Set up a default request diff --git a/tests/phpunit/tests/ajax/Response.php b/tests/phpunit/tests/ajax/Response.php index cf92699944..1ee2eb39ea 100644 --- a/tests/phpunit/tests/ajax/Response.php +++ b/tests/phpunit/tests/ajax/Response.php @@ -85,7 +85,7 @@ class Tests_Ajax_Response extends WP_UnitTestCase { $headers = xdebug_get_headers(); ob_end_clean(); - $this->assertTrue( in_array( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), $headers ) ); + $this->assertTrue( in_array( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), $headers, true ) ); } /** diff --git a/tests/phpunit/tests/basic.php b/tests/phpunit/tests/basic.php index 50dda1ec3f..396f108df9 100644 --- a/tests/phpunit/tests/basic.php +++ b/tests/phpunit/tests/basic.php @@ -22,7 +22,7 @@ class Tests_Basic extends WP_UnitTestCase { $package_json = json_decode( $package_json, true ); list( $version ) = explode( '-', $GLOBALS['wp_version'] ); // package.json uses x.y.z, so fill cleaned $wp_version for .0 releases - if ( 1 == substr_count( $version, '.' ) ) { + if ( 1 === substr_count( $version, '.' ) ) { $version .= '.0'; } $this->assertEquals( $version, $package_json['version'], "package.json's version needs to be updated to $version." ); diff --git a/tests/phpunit/tests/comment.php b/tests/phpunit/tests/comment.php index fdfb48be3f..720a805062 100644 --- a/tests/phpunit/tests/comment.php +++ b/tests/phpunit/tests/comment.php @@ -672,7 +672,7 @@ class Tests_Comment extends WP_UnitTestCase { // Check to see if a notification email was sent to the moderator `admin@example.org`. if ( isset( $GLOBALS['phpmailer']->mock_sent ) && ! empty( $GLOBALS['phpmailer']->mock_sent ) - && WP_TESTS_EMAIL == $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0] + && WP_TESTS_EMAIL === $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0] ) { $email_sent_when_comment_added = true; reset_phpmailer_instance(); @@ -700,7 +700,7 @@ class Tests_Comment extends WP_UnitTestCase { // Check to see if a notification email was sent to the post author `test@test.com`. if ( isset( $GLOBALS['phpmailer']->mock_sent ) && ! empty( $GLOBALS['phpmailer']->mock_sent ) - && 'test@test.com' == $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0] + && 'test@test.com' === $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0] ) { $email_sent_when_comment_approved = true; } else { @@ -722,7 +722,7 @@ class Tests_Comment extends WP_UnitTestCase { // Check to see if a notification email was sent to the post author `test@test.com`. if ( isset( $GLOBALS['phpmailer']->mock_sent ) && ! empty( $GLOBALS['phpmailer']->mock_sent ) && - 'test@test.com' == $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0] ) { + 'test@test.com' === $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0] ) { $email_sent_when_comment_added = true; reset_phpmailer_instance(); } else { diff --git a/tests/phpunit/tests/comment/walker.php b/tests/phpunit/tests/comment/walker.php index 5e589270c9..eadd9861e9 100644 --- a/tests/phpunit/tests/comment/walker.php +++ b/tests/phpunit/tests/comment/walker.php @@ -54,10 +54,10 @@ class Comment_Callback_Test { } public function comment( $comment, $args, $depth ) { - if ( 1 == $depth ) { + if ( 1 === $depth ) { $this->test_walker->assertTrue( $this->walker->has_children ); $this->test_walker->assertTrue( $args['has_children'] ); // Back compat - } elseif ( 2 == $depth ) { + } elseif ( 2 === $depth ) { $this->test_walker->assertFalse( $this->walker->has_children ); $this->test_walker->assertFalse( $args['has_children'] ); // Back compat } diff --git a/tests/phpunit/tests/compat.php b/tests/phpunit/tests/compat.php index b5b42d2a00..d70d0271b1 100644 --- a/tests/phpunit/tests/compat.php +++ b/tests/phpunit/tests/compat.php @@ -125,10 +125,10 @@ EOT; 'string', $heredoc, // object data - new classA(), - // undefined data + new ClassA(), + // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- intentionally undefined data @$undefined_var, - // unset data + // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- intentionally unset data @$unset_var, ); $outputs = array( @@ -315,7 +315,7 @@ EOT; } /* used in test_mb_substr_phpcore */ -class classA { +class ClassA { public function __toString() { return 'Class A object'; } diff --git a/tests/phpunit/tests/customize/manager.php b/tests/phpunit/tests/customize/manager.php index 1a0de4a1e2..f081245c6b 100644 --- a/tests/phpunit/tests/customize/manager.php +++ b/tests/phpunit/tests/customize/manager.php @@ -2668,7 +2668,7 @@ class Tests_WP_Customize_Manager extends WP_UnitTestCase { */ function filter_customize_dynamic_setting_args_for_test_dynamic_settings( $setting_args, $setting_id ) { $this->assertInternalType( 'string', $setting_id ); - if ( in_array( $setting_id, array( 'foo', 'bar' ) ) ) { + if ( in_array( $setting_id, array( 'foo', 'bar' ), true ) ) { $setting_args = array( 'default' => "dynamic_{$setting_id}_default" ); } return $setting_args; diff --git a/tests/phpunit/tests/customize/nav-menu-item-setting.php b/tests/phpunit/tests/customize/nav-menu-item-setting.php index 4b88c058e6..c80ce613b4 100644 --- a/tests/phpunit/tests/customize/nav-menu-item-setting.php +++ b/tests/phpunit/tests/customize/nav-menu-item-setting.php @@ -386,7 +386,7 @@ class Test_WP_Customize_Nav_Menu_Item_Setting extends WP_UnitTestCase { $menu_items = wp_get_nav_menu_items( $secondary_menu_id ); $db_ids = wp_list_pluck( $menu_items, 'db_id' ); $this->assertContains( $item_id, $db_ids ); - $i = array_search( $item_id, $db_ids ); + $i = array_search( $item_id, $db_ids, true ); $updated_item = $menu_items[ $i ]; $post_value['post_status'] = $post_value['status']; unset( $post_value['status'] ); @@ -676,7 +676,7 @@ class Test_WP_Customize_Nav_Menu_Item_Setting extends WP_UnitTestCase { $menu_items = wp_get_nav_menu_items( $secondary_menu_id ); $db_ids = wp_list_pluck( $menu_items, 'db_id' ); $this->assertContains( $item_id, $db_ids ); - $i = array_search( $item_id, $db_ids ); + $i = array_search( $item_id, $db_ids, true ); $updated_item = $menu_items[ $i ]; $post_value['post_status'] = $post_value['status']; unset( $post_value['status'] ); diff --git a/tests/phpunit/tests/customize/nav-menu-setting.php b/tests/phpunit/tests/customize/nav-menu-setting.php index b963a2a7a7..ffa8a1bc8d 100644 --- a/tests/phpunit/tests/customize/nav-menu-setting.php +++ b/tests/phpunit/tests/customize/nav-menu-setting.php @@ -224,7 +224,7 @@ class Test_WP_Customize_Nav_Menu_Setting extends WP_UnitTestCase { $menus = wp_get_nav_menus(); $menus_ids = wp_list_pluck( $menus, 'term_id' ); - $i = array_search( $menu_id, $menus_ids ); + $i = array_search( $menu_id, $menus_ids, true ); $this->assertInternalType( 'int', $i, 'Update-previewed menu does not appear in wp_get_nav_menus()' ); $filtered_menu = $menus[ $i ]; $this->assertEquals( 'Name 2 \\o/', $filtered_menu->name ); @@ -269,7 +269,7 @@ class Test_WP_Customize_Nav_Menu_Setting extends WP_UnitTestCase { $menus = wp_get_nav_menus(); $menus_ids = wp_list_pluck( $menus, 'term_id' ); - $i = array_search( $menu_id, $menus_ids ); + $i = array_search( $menu_id, $menus_ids, true ); $this->assertInternalType( 'int', $i, 'Insert-previewed menu was not injected into wp_get_nav_menus()' ); $filtered_menu = $menus[ $i ]; $this->assertEquals( 'New Menu Name 1 \\o/', $filtered_menu->name ); diff --git a/tests/phpunit/tests/date/query.php b/tests/phpunit/tests/date/query.php index 3afc4850d5..18c2c95218 100644 --- a/tests/phpunit/tests/date/query.php +++ b/tests/phpunit/tests/date/query.php @@ -1014,7 +1014,7 @@ class Tests_WP_Date_Query extends WP_UnitTestCase { // Invalid values. $days_of_year = array( -1, 0, 367 ); foreach ( $days_of_year as $day_of_year ) { - $this->assertFalse( @$this->q->validate_date_values( array( 'dayofyear' => $day_of_year ) ) ); + $this->assertFalse( $this->q->validate_date_values( array( 'dayofyear' => $day_of_year ) ) ); } } diff --git a/tests/phpunit/tests/db.php b/tests/phpunit/tests/db.php index 385c4e3dcd..0583ae132a 100644 --- a/tests/phpunit/tests/db.php +++ b/tests/phpunit/tests/db.php @@ -23,7 +23,7 @@ class Tests_DB extends WP_UnitTestCase { public static function setUpBeforeClass() { parent::setUpBeforeClass(); - self::$_wpdb = new wpdb_exposed_methods_for_testing(); + self::$_wpdb = new WpdbExposedMethodsForTesting(); } /** @@ -346,7 +346,7 @@ class Tests_DB extends WP_UnitTestCase { } public function filter_allowed_incompatible_sql_mode( $modes ) { - $pos = array_search( 'ONLY_FULL_GROUP_BY', $modes ); + $pos = array_search( 'ONLY_FULL_GROUP_BY', $modes, true ); $this->assertGreaterThanOrEqual( 0, $pos ); if ( false === $pos ) { @@ -365,6 +365,7 @@ class Tests_DB extends WP_UnitTestCase { global $wpdb; $id = 0; // This, obviously, is an incorrect prepare. + // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared $prepared = $wpdb->prepare( "SELECT * FROM $wpdb->users WHERE id = $id", $id ); $this->assertEquals( "SELECT * FROM $wpdb->users WHERE id = 0", $prepared ); } @@ -382,9 +383,11 @@ class Tests_DB extends WP_UnitTestCase { function test_prepare_sprintf_invalid_args() { global $wpdb; + // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged $prepared = @$wpdb->prepare( "SELECT * FROM $wpdb->users WHERE id = %d AND user_login = %s", 1, array( 'admin' ) ); $this->assertEquals( "SELECT * FROM $wpdb->users WHERE id = 1 AND user_login = ''", $prepared ); + // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged $prepared = @$wpdb->prepare( "SELECT * FROM $wpdb->users WHERE id = %d AND user_login = %s", array( 1 ), 'admin' ); $this->assertEquals( "SELECT * FROM $wpdb->users WHERE id = 0 AND user_login = 'admin'", $prepared ); } @@ -402,9 +405,11 @@ class Tests_DB extends WP_UnitTestCase { function test_prepare_vsprintf_invalid_args() { global $wpdb; + // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged $prepared = @$wpdb->prepare( "SELECT * FROM $wpdb->users WHERE id = %d AND user_login = %s", array( 1, array( 'admin' ) ) ); $this->assertEquals( "SELECT * FROM $wpdb->users WHERE id = 1 AND user_login = ''", $prepared ); + // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged $prepared = @$wpdb->prepare( "SELECT * FROM $wpdb->users WHERE id = %d AND user_login = %s", array( array( 1 ), 'admin' ) ); $this->assertEquals( "SELECT * FROM $wpdb->users WHERE id = 0 AND user_login = 'admin'", $prepared ); } @@ -420,6 +425,7 @@ class Tests_DB extends WP_UnitTestCase { // $query is the first argument to be passed to wpdb::prepare() array_unshift( $args, $query ); + // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged $prepared = @call_user_func_array( array( $wpdb, 'prepare' ), $args ); $this->assertEquals( $expected, $prepared ); } @@ -587,6 +593,7 @@ class Tests_DB extends WP_UnitTestCase { $wpdb->last_result = $last_result; + // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared $result = $wpdb->get_col( $query, $column ); if ( $query ) { @@ -1043,7 +1050,7 @@ class Tests_DB extends WP_UnitTestCase { $expected_charset = $wpdb->get_col_charset( $wpdb->posts, 'post_content' ); } - if ( ! in_array( $expected_charset, array( 'utf8', 'utf8mb4', 'latin1' ) ) ) { + if ( ! in_array( $expected_charset, array( 'utf8', 'utf8mb4', 'latin1' ), true ) ) { $this->markTestSkipped( 'This test only works with utf8, utf8mb4 or latin1 character sets' ); } @@ -1116,7 +1123,7 @@ class Tests_DB extends WP_UnitTestCase { array( '%s', '%s' ) ); - $row = $wpdb->get_row( "SELECT * FROM $wpdb->postmeta WHERE meta_key='$key'" ); + $row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE meta_key=%s", $key ) ); $this->assertNull( $row->meta_value ); } @@ -1139,7 +1146,7 @@ class Tests_DB extends WP_UnitTestCase { array( '%s', '%s' ) ); - $row = $wpdb->get_row( "SELECT * FROM $wpdb->postmeta WHERE meta_key='$key'" ); + $row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE meta_key=%s", $key ) ); $this->assertSame( $value, $row->meta_value ); @@ -1154,7 +1161,7 @@ class Tests_DB extends WP_UnitTestCase { array( '%s', '%s' ) ); - $row = $wpdb->get_row( "SELECT * FROM $wpdb->postmeta WHERE meta_key='$key'" ); + $row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE meta_key=%s", $key ) ); $this->assertNull( $row->meta_value ); } @@ -1177,7 +1184,7 @@ class Tests_DB extends WP_UnitTestCase { array( '%s', '%s' ) ); - $row = $wpdb->get_row( "SELECT * FROM $wpdb->postmeta WHERE meta_key='$key'" ); + $row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE meta_key=%s", $key ) ); $this->assertNull( $row->meta_value ); @@ -1192,7 +1199,7 @@ class Tests_DB extends WP_UnitTestCase { array( '%s', '%s' ) ); - $row = $wpdb->get_row( "SELECT * FROM $wpdb->postmeta WHERE meta_key='$key'" ); + $row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE meta_key=%s", $key ) ); $this->assertSame( $value, $row->meta_value ); } @@ -1215,7 +1222,7 @@ class Tests_DB extends WP_UnitTestCase { array( '%s', '%s' ) ); - $row = $wpdb->get_row( "SELECT * FROM $wpdb->postmeta WHERE meta_key='$key'" ); + $row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE meta_key=%s", $key ) ); $this->assertNull( $row->meta_value ); @@ -1228,7 +1235,7 @@ class Tests_DB extends WP_UnitTestCase { array( '%s', '%s' ) ); - $row = $wpdb->get_row( "SELECT * FROM $wpdb->postmeta WHERE meta_key='$key'" ); + $row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE meta_key=%s", $key ) ); $this->assertNull( $row ); } @@ -1572,6 +1579,7 @@ class Tests_DB extends WP_UnitTestCase { $sql = str_replace( '{ESCAPE}', $escape, $sql ); + // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared $actual = $wpdb->prepare( $sql, $values ); $this->assertEquals( $expected, $actual ); @@ -1653,6 +1661,8 @@ class Tests_DB extends WP_UnitTestCase { $wpdb->query( "CREATE TABLE {$wpdb->prefix}test_placeholder( a VARCHAR(100) );" ); $sql = $wpdb->prepare( "INSERT INTO {$wpdb->prefix}test_placeholder VALUES(%s)", $value ); + + // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared $wpdb->query( $sql ); $actual = $wpdb->get_var( "SELECT a FROM {$wpdb->prefix}test_placeholder" ); @@ -1667,6 +1677,7 @@ class Tests_DB extends WP_UnitTestCase { global $wpdb; $sql = $wpdb->prepare( ' %s %1$c ', 'foo' ); + // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared $sql = $wpdb->prepare( " $sql %s ", 'foo' ); $this->assertEquals( " 'foo' {$wpdb->placeholder_escape()}1\$c 'foo' ", $sql ); diff --git a/tests/phpunit/tests/db/charset.php b/tests/phpunit/tests/db/charset.php index 6f0de5982c..3089ec9a74 100644 --- a/tests/phpunit/tests/db/charset.php +++ b/tests/phpunit/tests/db/charset.php @@ -27,7 +27,7 @@ class Tests_DB_Charset extends WP_UnitTestCase { require_once( dirname( dirname( __FILE__ ) ) . '/db.php' ); - self::$_wpdb = new wpdb_exposed_methods_for_testing(); + self::$_wpdb = new WpdbExposedMethodsForTesting(); if ( self::$_wpdb->use_mysqli ) { self::$server_info = mysqli_get_server_info( self::$_wpdb->dbh ); diff --git a/tests/phpunit/tests/dbdelta.php b/tests/phpunit/tests/dbdelta.php index 5b44094767..30d0867033 100644 --- a/tests/phpunit/tests/dbdelta.php +++ b/tests/phpunit/tests/dbdelta.php @@ -33,18 +33,22 @@ class Tests_dbDelta extends WP_UnitTestCase { // Forcing MyISAM, because InnoDB only started supporting FULLTEXT indexes in MySQL 5.7. $wpdb->query( - " - CREATE TABLE {$wpdb->prefix}dbdelta_test ( - id bigint(20) NOT NULL AUTO_INCREMENT, - column_1 varchar(255) NOT NULL, - column_2 text, - column_3 blob, - PRIMARY KEY (id), - KEY key_1 (column_1($this->max_index_length)), - KEY compound_key (id,column_1($this->max_index_length)), - FULLTEXT KEY fulltext_key (column_1) - ) ENGINE=MyISAM - " + $wpdb->prepare( + " + CREATE TABLE {$wpdb->prefix}dbdelta_test ( + id bigint(20) NOT NULL AUTO_INCREMENT, + column_1 varchar(255) NOT NULL, + column_2 text, + column_3 blob, + PRIMARY KEY (id), + KEY key_1 (column_1(%d)), + KEY compound_key (id,column_1(%d)), + FULLTEXT KEY fulltext_key (column_1) + ) ENGINE=MyISAM + ", + $this->max_index_length, + $this->max_index_length + ) ); parent::setUp(); @@ -299,6 +303,7 @@ class Tests_dbDelta extends WP_UnitTestCase { protected function assertTableRowHasValue( $column, $value, $table ) { global $wpdb; + // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared $table_row = $wpdb->get_row( "select $column from {$table} where $column = '$value'" ); $expected = (object) array( @@ -317,7 +322,8 @@ class Tests_dbDelta extends WP_UnitTestCase { protected function assertTableHasColumn( $column, $table ) { global $wpdb; - $table_fields = $wpdb->get_results( "DESCRIBE {$table}" ); + // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared + $table_fields = $wpdb->get_results( "DESCRIBE $table" ); $this->assertCount( 1, wp_list_filter( $table_fields, array( 'Field' => $column ) ) ); } @@ -333,7 +339,8 @@ class Tests_dbDelta extends WP_UnitTestCase { protected function assertTableHasPrimaryKey( $column, $table ) { global $wpdb; - $table_indices = $wpdb->get_results( "SHOW INDEX FROM {$table}" ); + // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared + $table_indices = $wpdb->get_results( "SHOW INDEX FROM $table" ); $this->assertCount( 1, @@ -358,7 +365,8 @@ class Tests_dbDelta extends WP_UnitTestCase { global $wpdb; - $table_fields = $wpdb->get_results( "DESCRIBE {$table}" ); + // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared + $table_fields = $wpdb->get_results( "DESCRIBE $table" ); $this->assertCount( 0, wp_list_filter( $table_fields, array( 'Field' => $column ) ) ); } @@ -385,15 +393,18 @@ class Tests_dbDelta extends WP_UnitTestCase { KEY a_key (a) ) ENGINE=InnoDB ROW_FORMAT=DYNAMIC"; + // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared $wpdb->query( $create ); + // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared $index = $wpdb->get_row( "SHOW INDEXES FROM $table_name WHERE Key_name='a_key';" ); $actual = dbDelta( $create, false ); + // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared $wpdb->query( "DROP TABLE IF EXISTS $table_name;" ); - if ( 191 != $index->Sub_part ) { + if ( 191 !== $index->Sub_part ) { $this->markTestSkipped( 'This test requires the index to be truncated.' ); } @@ -527,6 +538,7 @@ class Tests_dbDelta extends WP_UnitTestCase { ) "; + // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared $wpdb->query( $schema ); $updates = dbDelta( $schema, false ); @@ -556,6 +568,7 @@ class Tests_dbDelta extends WP_UnitTestCase { ) ENGINE=MyISAM; "; + // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared $wpdb->query( $schema ); $updates = dbDelta( $schema, false ); @@ -602,6 +615,7 @@ class Tests_dbDelta extends WP_UnitTestCase { ) "; + // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared $wpdb->query( $schema ); $updates = dbDelta( $schema ); @@ -998,6 +1012,7 @@ class Tests_dbDelta extends WP_UnitTestCase { ) "; + // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared $wpdb->query( $schema ); $schema_update = " diff --git a/tests/phpunit/tests/external-http/basic.php b/tests/phpunit/tests/external-http/basic.php index 8799746692..8596cbd472 100644 --- a/tests/phpunit/tests/external-http/basic.php +++ b/tests/phpunit/tests/external-http/basic.php @@ -13,7 +13,7 @@ class Tests_External_HTTP_Basic extends WP_UnitTestCase { preg_match( '#Recommendations.*PHP version ([0-9.]*)#s', $readme, $matches ); $response = wp_remote_get( 'https://secure.php.net/supported-versions.php' ); - if ( 200 != wp_remote_retrieve_response_code( $response ) ) { + if ( 200 !== wp_remote_retrieve_response_code( $response ) ) { $this->fail( 'Could not contact PHP.net to check versions.' ); } $php = wp_remote_retrieve_body( $response ); @@ -25,7 +25,7 @@ class Tests_External_HTTP_Basic extends WP_UnitTestCase { preg_match( '#Recommendations.*MySQL version ([0-9.]*)#s', $readme, $matches ); $response = wp_remote_get( "https://dev.mysql.com/doc/relnotes/mysql/{$matches[1]}/en/" ); - if ( 200 != wp_remote_retrieve_response_code( $response ) ) { + if ( 200 !== wp_remote_retrieve_response_code( $response ) ) { $this->fail( 'Could not contact dev.MySQL.com to check versions.' ); } $mysql = wp_remote_retrieve_body( $response ); diff --git a/tests/phpunit/tests/feed/atom.php b/tests/phpunit/tests/feed/atom.php index 9d6e3f8eb5..627beda0e1 100644 --- a/tests/phpunit/tests/feed/atom.php +++ b/tests/phpunit/tests/feed/atom.php @@ -71,6 +71,7 @@ class Tests_Feeds_Atom extends WP_UnitTestCase { // Nasty hack! In the future it would better to leverage do_feed( 'atom' ). global $post; try { + // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged @require( ABSPATH . 'wp-includes/feed-atom.php' ); $out = ob_get_clean(); } catch ( Exception $e ) { @@ -162,7 +163,7 @@ class Tests_Feeds_Atom extends WP_UnitTestCase { // Link rel="alternate" $link_alts = xml_find( $entries[ $key ]['child'], 'link' ); foreach ( $link_alts as $link_alt ) { - if ( 'alternate' == $link_alt['attributes']['rel'] ) { + if ( 'alternate' === $link_alt['attributes']['rel'] ) { $this->assertEquals( get_permalink( $post ), $link_alt['attributes']['href'] ); } } @@ -185,7 +186,7 @@ class Tests_Feeds_Atom extends WP_UnitTestCase { } $categories = xml_find( $entries[ $key ]['child'], 'category' ); foreach ( $categories as $category ) { - $this->assertTrue( in_array( $category['attributes']['term'], $terms ) ); + $this->assertTrue( in_array( $category['attributes']['term'], $terms, true ) ); } unset( $terms ); @@ -198,7 +199,7 @@ class Tests_Feeds_Atom extends WP_UnitTestCase { // Link rel="replies" $link_replies = xml_find( $entries[ $key ]['child'], 'link' ); foreach ( $link_replies as $link_reply ) { - if ( 'replies' == $link_reply['attributes']['rel'] && 'application/atom+xml' == $link_reply['attributes']['type'] ) { + if ( 'replies' === $link_reply['attributes']['rel'] && 'application/atom+xml' === $link_reply['attributes']['type'] ) { $this->assertEquals( get_post_comments_feed_link( $post->ID, 'atom' ), $link_reply['attributes']['href'] ); } } diff --git a/tests/phpunit/tests/feed/rss2.php b/tests/phpunit/tests/feed/rss2.php index 8263fde4dd..32d950a1a5 100644 --- a/tests/phpunit/tests/feed/rss2.php +++ b/tests/phpunit/tests/feed/rss2.php @@ -83,6 +83,7 @@ class Tests_Feeds_RSS2 extends WP_UnitTestCase { // Nasty hack! In the future it would better to leverage do_feed( 'rss2' ). global $post; try { + // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged @require( ABSPATH . 'wp-includes/feed-rss2.php' ); $out = ob_get_clean(); } catch ( Exception $e ) { diff --git a/tests/phpunit/tests/file.php b/tests/phpunit/tests/file.php index d36824e4df..481b3362c9 100644 --- a/tests/phpunit/tests/file.php +++ b/tests/phpunit/tests/file.php @@ -208,7 +208,7 @@ class Tests_File extends WP_UnitTestCase { $this->assertLessThan( 10, $time_taken, 'verify_file_signature() took longer than 10 seconds.' ); // Check to see if the system parameters prevent signature verifications. - if ( is_wp_error( $verify ) && 'signature_verification_unsupported' == $verify->get_error_code() ) { + if ( is_wp_error( $verify ) && 'signature_verification_unsupported' === $verify->get_error_code() ) { $this->markTestSkipped( 'This system does not support Signature Verification.' ); } @@ -228,7 +228,7 @@ class Tests_File extends WP_UnitTestCase { $verify = verify_file_signature( $file, $expected_signature, 'WordPress' ); unlink( $file ); - if ( is_wp_error( $verify ) && 'signature_verification_unsupported' == $verify->get_error_code() ) { + if ( is_wp_error( $verify ) && 'signature_verification_unsupported' === $verify->get_error_code() ) { $this->markTestSkipped( 'This system does not support Signature Verification.' ); } diff --git a/tests/phpunit/tests/formatting/WPSpecialchars.php b/tests/phpunit/tests/formatting/WPSpecialchars.php index 09d51d58d8..97ce8e084c 100644 --- a/tests/phpunit/tests/formatting/WPSpecialchars.php +++ b/tests/phpunit/tests/formatting/WPSpecialchars.php @@ -17,7 +17,7 @@ class Tests_Formatting_WPSpecialchars extends WP_UnitTestCase { // Allowed entities should be unchanged foreach ( $allowedentitynames as $ent ) { - if ( 'apos' == $ent ) { + if ( 'apos' === $ent ) { // But for some reason, PHP doesn't allow ' continue; } diff --git a/tests/phpunit/tests/formatting/WPTexturize.php b/tests/phpunit/tests/formatting/WPTexturize.php index 5b6a11cd08..24b0b26883 100644 --- a/tests/phpunit/tests/formatting/WPTexturize.php +++ b/tests/phpunit/tests/formatting/WPTexturize.php @@ -1576,7 +1576,7 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase { case '‘': return '!openq1!'; case '’': - if ( 'apostrophe' == $context ) { + if ( 'apostrophe' === $context ) { return '!apos!'; } else { return '!closeq1!'; @@ -2001,7 +2001,7 @@ String with a number followed by a single quote ‘Expendables 3’ vest case '‘': return '!q1!'; case '’': - if ( 'apostrophe' == $context ) { + if ( 'apostrophe' === $context ) { return '!apos!'; } else { return '!q1!'; diff --git a/tests/phpunit/tests/functions.php b/tests/phpunit/tests/functions.php index a28724db27..53f6e2cd5c 100644 --- a/tests/phpunit/tests/functions.php +++ b/tests/phpunit/tests/functions.php @@ -844,7 +844,7 @@ class Tests_Functions extends WP_UnitTestCase { $charsets = mb_detect_order(); $old_charsets = $charsets; - if ( ! in_array( 'EUC-JP', $charsets ) ) { + if ( ! in_array( 'EUC-JP', $charsets, true ) ) { $charsets[] = 'EUC-JP'; mb_detect_order( $charsets ); } @@ -869,7 +869,7 @@ class Tests_Functions extends WP_UnitTestCase { $charsets = mb_detect_order(); $old_charsets = $charsets; - if ( ! in_array( 'EUC-JP', $charsets ) ) { + if ( ! in_array( 'EUC-JP', $charsets, true ) ) { $charsets[] = 'EUC-JP'; mb_detect_order( $charsets ); } @@ -965,8 +965,8 @@ class Tests_Functions extends WP_UnitTestCase { public function test_wp_ext2type() { $extensions = wp_get_ext_types(); - foreach ( $extensions as $type => $extensionList ) { - foreach ( $extensionList as $extension ) { + foreach ( $extensions as $type => $extension_list ) { + foreach ( $extension_list as $extension ) { $this->assertEquals( $type, wp_ext2type( $extension ) ); $this->assertEquals( $type, wp_ext2type( strtoupper( $extension ) ) ); } diff --git a/tests/phpunit/tests/functions/deprecated.php b/tests/phpunit/tests/functions/deprecated.php index c4f8793238..3bd6116f48 100644 --- a/tests/phpunit/tests/functions/deprecated.php +++ b/tests/phpunit/tests/functions/deprecated.php @@ -135,7 +135,7 @@ class Test_Functions_Deprecated extends WP_UnitTestCase { $key = 'file'; } foreach ( $search as $v ) { - if ( $name == $v[ $key ] ) { + if ( $name === $v[ $key ] ) { return $v; } } diff --git a/tests/phpunit/tests/http/base.php b/tests/phpunit/tests/http/base.php index 4881d28cde..6cc6cc7d67 100644 --- a/tests/phpunit/tests/http/base.php +++ b/tests/phpunit/tests/http/base.php @@ -54,7 +54,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { // Disable all transports aside from this one. foreach ( array( 'curl', 'streams', 'fsockopen' ) as $t ) { remove_filter( "use_{$t}_transport", '__return_false' ); // Just strip them all - if ( $t != $this->transport ) { + if ( $t !== $this->transport ) { add_filter( "use_{$t}_transport", '__return_false' ); // and add it back if need be.. } } @@ -247,7 +247,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { $headers[ $parts[0] ] = $parts[1]; } - $this->assertTrue( isset( $headers['test1'] ) && 'test' == $headers['test1'] ); + $this->assertTrue( isset( $headers['test1'] ) && 'test' === $headers['test1'] ); $this->assertTrue( isset( $headers['test2'] ) && '0' === $headers['test2'] ); // cURL/HTTP Extension Note: Will never pass, cURL does not pass headers with an empty value. // Should it be that empty headers with empty values are NOT sent? diff --git a/tests/phpunit/tests/image/base.php b/tests/phpunit/tests/image/base.php index e0530e8881..3c32052b63 100644 --- a/tests/phpunit/tests/image/base.php +++ b/tests/phpunit/tests/image/base.php @@ -75,7 +75,7 @@ abstract class WP_Image_UnitTestCase extends WP_UnitTestCase { protected function assertImageDimensions( $filename, $width, $height ) { $detected_width = 0; $detected_height = 0; - $image_size = @getimagesize( $filename ); + $image_size = getimagesize( $filename ); if ( isset( $image_size[0] ) ) { $detected_width = $image_size[0]; diff --git a/tests/phpunit/tests/image/siteIcon.php b/tests/phpunit/tests/image/siteIcon.php index 891b2095fc..dad3ddba52 100644 --- a/tests/phpunit/tests/image/siteIcon.php +++ b/tests/phpunit/tests/image/siteIcon.php @@ -55,7 +55,7 @@ class Tests_WP_Site_Icon extends WP_UnitTestCase { $this->assertEquals( $sizes, $image_sizes ); // Remove custom size. - unset( $this->wp_site_icon->site_icon_sizes[ array_search( 321, $this->wp_site_icon->site_icon_sizes ) ] ); + unset( $this->wp_site_icon->site_icon_sizes[ array_search( 321, $this->wp_site_icon->site_icon_sizes, true ) ] ); // Remove the filter we added remove_filter( 'site_icon_image_sizes', array( $this, '_custom_test_sizes' ) ); } @@ -95,7 +95,7 @@ class Tests_WP_Site_Icon extends WP_UnitTestCase { $this->assertEquals( $sizes, $image_sizes ); // Remove custom size. - unset( $this->wp_site_icon->site_icon_sizes[ array_search( 321, $this->wp_site_icon->site_icon_sizes ) ] ); + unset( $this->wp_site_icon->site_icon_sizes[ array_search( 321, $this->wp_site_icon->site_icon_sizes, true ) ] ); } function test_create_attachment_object() { diff --git a/tests/phpunit/tests/import/import.php b/tests/phpunit/tests/import/import.php index 0b85d261d4..e005826a18 100644 --- a/tests/phpunit/tests/import/import.php +++ b/tests/phpunit/tests/import/import.php @@ -28,6 +28,7 @@ class Tests_Import_Import extends WP_Import_UnitTestCase { global $wpdb; // crude but effective: make sure there's no residual data in the main tables foreach ( array( 'posts', 'postmeta', 'comments', 'terms', 'term_taxonomy', 'term_relationships', 'users', 'usermeta' ) as $table ) { + // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared $wpdb->query( "DELETE FROM {$wpdb->$table}" ); } } diff --git a/tests/phpunit/tests/kses.php b/tests/phpunit/tests/kses.php index 6cfa8df881..a36cdf4f93 100644 --- a/tests/phpunit/tests/kses.php +++ b/tests/phpunit/tests/kses.php @@ -148,7 +148,7 @@ EOF; ); foreach ( $bad as $k => $x ) { $result = wp_kses_bad_protocol( wp_kses_normalize_entities( $x ), wp_allowed_protocols() ); - if ( ! empty( $result ) && $result != 'alert(1);' && $result != 'alert(1)' ) { + if ( ! empty( $result ) && 'alert(1);' !== $result && 'alert(1)' !== $result ) { switch ( $k ) { case 6: $this->assertEquals( 'javascript&#0000058alert(1);', $result ); @@ -183,7 +183,7 @@ EOF; ); foreach ( $safe as $x ) { $result = wp_kses_bad_protocol( wp_kses_normalize_entities( $x ), array( 'http', 'https', 'dummy' ) ); - if ( $result != $x && $result != 'http://example.org/' ) { + if ( $result !== $x && 'http://example.org/' !== $result ) { $this->fail( "wp_kses_bad_protocol incorrectly blocked $x" ); } } @@ -192,17 +192,17 @@ EOF; public function test_hackers_attacks() { $xss = simplexml_load_file( DIR_TESTDATA . '/formatting/xssAttacks.xml' ); foreach ( $xss->attack as $attack ) { - if ( in_array( $attack->name, array( 'IMG Embedded commands 2', 'US-ASCII encoding', 'OBJECT w/Flash 2', 'Character Encoding Example' ) ) ) { + if ( in_array( (string) $attack->name, array( 'IMG Embedded commands 2', 'US-ASCII encoding', 'OBJECT w/Flash 2', 'Character Encoding Example' ), true ) ) { continue; } $code = (string) $attack->code; - if ( $code == 'See Below' ) { + if ( 'See Below' === $code ) { continue; } - if ( substr( $code, 0, 4 ) == 'perl' ) { + if ( substr( $code, 0, 4 ) === 'perl' ) { $pos = strpos( $code, '"' ) + 1; $code = substr( $code, $pos, strrpos( $code, '"' ) - $pos ); $code = str_replace( '\0', "\0", $code ); @@ -210,7 +210,7 @@ EOF; $result = trim( wp_kses_data( $code ) ); - if ( $result == '' || $result == 'XSS' || $result == 'alert("XSS");' || $result == "alert('XSS');" ) { + if ( in_array( $result, array( '', 'XSS', 'alert("XSS");', "alert('XSS');" ), true ) ) { continue; } @@ -324,7 +324,7 @@ EOF; } function _wp_kses_allowed_html_filter( $html, $context ) { - if ( 'post' == $context ) { + if ( 'post' === $context ) { return array( 'a' => array( 'href' => true ) ); } else { return array( 'a' => array( 'href' => false ) ); diff --git a/tests/phpunit/tests/l10n.php b/tests/phpunit/tests/l10n.php index 7b34d32b4e..7c8e492fc5 100644 --- a/tests/phpunit/tests/l10n.php +++ b/tests/phpunit/tests/l10n.php @@ -75,16 +75,16 @@ class Tests_L10n extends WP_UnitTestCase { $this->assertEqualSets( $textdomains_expected, array_keys( $installed_translations ) ); $this->assertNotEmpty( $installed_translations['default']['en_GB'] ); - $data_en_GB = $installed_translations['default']['en_GB']; - $this->assertEquals( '2016-10-26 00:01+0200', $data_en_GB['PO-Revision-Date'] ); - $this->assertEquals( 'Development (4.4.x)', $data_en_GB['Project-Id-Version'] ); - $this->assertEquals( 'Poedit 1.8.10', $data_en_GB['X-Generator'] ); + $data_en_gb = $installed_translations['default']['en_GB']; + $this->assertEquals( '2016-10-26 00:01+0200', $data_en_gb['PO-Revision-Date'] ); + $this->assertEquals( 'Development (4.4.x)', $data_en_gb['Project-Id-Version'] ); + $this->assertEquals( 'Poedit 1.8.10', $data_en_gb['X-Generator'] ); $this->assertNotEmpty( $installed_translations['admin']['es_ES'] ); - $data_es_ES = $installed_translations['admin']['es_ES']; - $this->assertEquals( '2016-10-25 18:29+0200', $data_es_ES['PO-Revision-Date'] ); - $this->assertEquals( 'Administration', $data_es_ES['Project-Id-Version'] ); - $this->assertEquals( 'Poedit 1.8.10', $data_es_ES['X-Generator'] ); + $data_es_es = $installed_translations['admin']['es_ES']; + $this->assertEquals( '2016-10-25 18:29+0200', $data_es_es['PO-Revision-Date'] ); + $this->assertEquals( 'Administration', $data_es_es['Project-Id-Version'] ); + $this->assertEquals( 'Poedit 1.8.10', $data_es_es['X-Generator'] ); } /** diff --git a/tests/phpunit/tests/l10n/loadTextdomainJustInTime.php b/tests/phpunit/tests/l10n/loadTextdomainJustInTime.php index 7fb85a5427..ea35bbfcfd 100644 --- a/tests/phpunit/tests/l10n/loadTextdomainJustInTime.php +++ b/tests/phpunit/tests/l10n/loadTextdomainJustInTime.php @@ -175,15 +175,15 @@ class Tests_L10n_loadTextdomainJustInTime extends WP_UnitTestCase { require_once DIR_TESTDATA . '/plugins/internationalized-plugin.php'; switch_to_locale( 'de_DE' ); - $expected_de_DE = i18n_plugin_test(); + $expected_de_de = i18n_plugin_test(); switch_to_locale( 'es_ES' ); - $expected_es_ES = i18n_plugin_test(); + $expected_es_es = i18n_plugin_test(); restore_current_locale(); - $this->assertSame( 'Das ist ein Dummy Plugin', $expected_de_DE ); - $this->assertSame( 'This is a dummy plugin', $expected_es_ES ); + $this->assertSame( 'Das ist ein Dummy Plugin', $expected_de_de ); + $this->assertSame( 'This is a dummy plugin', $expected_es_es ); } /** diff --git a/tests/phpunit/tests/l10n/localeSwitcher.php b/tests/phpunit/tests/l10n/localeSwitcher.php index f100c8a1db..0621092165 100644 --- a/tests/phpunit/tests/l10n/localeSwitcher.php +++ b/tests/phpunit/tests/l10n/localeSwitcher.php @@ -86,25 +86,25 @@ class Tests_Locale_Switcher extends WP_UnitTestCase { switch_to_locale( 'de_DE' ); - $wp_locale_de_DE = clone $wp_locale; + $wp_locale_de_de = clone $wp_locale; // Cleanup. restore_previous_locale(); - $this->assertEqualSetsWithIndex( $expected, $wp_locale_de_DE->number_format ); + $this->assertEqualSetsWithIndex( $expected, $wp_locale_de_de->number_format ); } public function test_switch_to_locale_en_US() { switch_to_locale( 'en_GB' ); - $locale_en_GB = get_locale(); + $locale_en_gb = get_locale(); switch_to_locale( 'en_US' ); - $locale_en_US = get_locale(); + $locale_en_us = get_locale(); // Cleanup. restore_current_locale(); - $this->assertSame( 'en_GB', $locale_en_GB ); - $this->assertSame( 'en_US', $locale_en_US ); + $this->assertSame( 'en_GB', $locale_en_gb ); + $this->assertSame( 'en_US', $locale_en_us ); } public function test_switch_to_locale_multiple_times() { diff --git a/tests/phpunit/tests/link/themeFile.php b/tests/phpunit/tests/link/themeFile.php index fe0dbcfe42..9497b71e14 100644 --- a/tests/phpunit/tests/link/themeFile.php +++ b/tests/phpunit/tests/link/themeFile.php @@ -8,9 +8,11 @@ class Test_Theme_File extends WP_UnitTestCase { if ( ! function_exists( 'symlink' ) ) { self::markTestSkipped( 'symlink() is not available.' ); } + // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged if ( ! @symlink( DIR_TESTDATA . '/theme-file-parent', WP_CONTENT_DIR . '/themes/theme-file-parent' ) ) { self::markTestSkipped( 'Could not create parent symlink.' ); } + // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged if ( ! @symlink( DIR_TESTDATA . '/theme-file-child', WP_CONTENT_DIR . '/themes/theme-file-child' ) ) { self::markTestSkipped( 'Could not create child symlink.' ); } diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php index 112382462a..c5f329aace 100644 --- a/tests/phpunit/tests/media.php +++ b/tests/phpunit/tests/media.php @@ -1256,7 +1256,7 @@ EOF; * @ticket 33016 */ function filter_wp_embed_shortcode_custom( $content, $url ) { - if ( 'https://www.example.com/?video=1' == $url ) { + if ( 'https://www.example.com/?video=1' === $url ) { $content = '@embed URL was replaced@'; } return $content; @@ -1446,7 +1446,7 @@ EOF; foreach ( $image_meta['sizes'] as $name => $size ) { // Whitelist the sizes that should be included so we pick up 'medium_large' in 4.4. - if ( in_array( $name, $intermediates ) ) { + if ( in_array( $name, $intermediates, true ) ) { $expected .= $uploads_dir_url . $year_month . '/' . $size['file'] . ' ' . $size['width'] . 'w, '; } } @@ -1491,7 +1491,7 @@ EOF; foreach ( $image_meta['sizes'] as $name => $size ) { // Whitelist the sizes that should be included so we pick up 'medium_large' in 4.4. - if ( in_array( $name, $intermediates ) ) { + if ( in_array( $name, $intermediates, true ) ) { $expected .= $uploads_dir_url . $size['file'] . ' ' . $size['width'] . 'w, '; } } @@ -1568,7 +1568,7 @@ EOF; foreach ( $image_meta['sizes'] as $name => $size ) { // Whitelist the sizes that should be included so we pick up 'medium_large' in 4.4. - if ( in_array( $name, $intermediates ) ) { + if ( in_array( $name, $intermediates, true ) ) { $expected .= $uploads_dir_url . $year_month . '/' . $size['file'] . ' ' . $size['width'] . 'w, '; } } @@ -1847,7 +1847,7 @@ EOF; foreach ( $image_meta['sizes'] as $name => $size ) { // Whitelist the sizes that should be included so we pick up 'medium_large' in 4.4. - if ( in_array( $name, $intermediates ) ) { + if ( in_array( $name, $intermediates, true ) ) { $expected .= $uploads_dir . $year_month . '/' . $size['file'] . ' ' . $size['width'] . 'w, '; } } diff --git a/tests/phpunit/tests/meta.php b/tests/phpunit/tests/meta.php index b20f2be90d..c2cc6663b9 100644 --- a/tests/phpunit/tests/meta.php +++ b/tests/phpunit/tests/meta.php @@ -370,6 +370,7 @@ class Tests_Meta extends WP_UnitTestCase { $string_mid = "{$meta_id}.0"; + // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison -- intentional implicit casting check $this->assertTrue( floor( $string_mid ) == $string_mid ); $this->assertNotEquals( false, get_metadata_by_mid( 'user', $string_mid ) ); $this->assertNotEquals( false, update_metadata_by_mid( 'user', $string_mid, 'meta_new_value_2' ) ); diff --git a/tests/phpunit/tests/meta/registerMeta.php b/tests/phpunit/tests/meta/registerMeta.php index 6a7a4c830e..334a2320d0 100644 --- a/tests/phpunit/tests/meta/registerMeta.php +++ b/tests/phpunit/tests/meta/registerMeta.php @@ -505,7 +505,7 @@ class Tests_Meta_Register_Meta extends WP_UnitTestCase { } public function filter_get_object_subtype_for_customtype( $subtype, $object_id ) { - if ( $object_id % 2 === 1 ) { + if ( 1 === ( $object_id % 2 ) ) { return 'odd'; } diff --git a/tests/phpunit/tests/multisite.php b/tests/phpunit/tests/multisite.php index 6ff0743991..4d25ade892 100644 --- a/tests/phpunit/tests/multisite.php +++ b/tests/phpunit/tests/multisite.php @@ -31,7 +31,7 @@ if ( is_multisite() ) : wpmu_log_new_registrations( 1, 1 ); // currently there is no wrapper function for the registration_log - $reg_blog = $wpdb->get_col( "SELECT email FROM {$wpdb->registration_log} WHERE {$wpdb->registration_log}.blog_id = 1 AND IP LIKE '" . $ip . "'" ); + $reg_blog = $wpdb->get_col( $wpdb->prepare( "SELECT email FROM {$wpdb->registration_log} WHERE {$wpdb->registration_log}.blog_id = 1 AND IP LIKE %s", $ip ) ); $this->assertEquals( $user->user_email, $reg_blog[ count( $reg_blog ) - 1 ] ); } } diff --git a/tests/phpunit/tests/multisite/getSpaceUsed.php b/tests/phpunit/tests/multisite/getSpaceUsed.php index e386634616..7d6d33304c 100644 --- a/tests/phpunit/tests/multisite/getSpaceUsed.php +++ b/tests/phpunit/tests/multisite/getSpaceUsed.php @@ -28,7 +28,7 @@ if ( is_multisite() ) : // Our comparison of space relies on an initial value of 0. If a previous test has failed or if the // src directory already contains a content directory with site content, then the initial expectation // will be polluted. We create sites until an empty one is available. - while ( 0 != get_space_used() ) { + while ( 0 !== get_space_used() ) { restore_current_blog(); $blog_id = self::factory()->blog->create(); switch_to_blog( $blog_id ); @@ -64,7 +64,7 @@ if ( is_multisite() ) : // We don't rely on an initial value of 0 for space used, but should have a clean space available // so that we can remove any uploaded files and directories without concern of a conflict with // existing content directories in src. - while ( 0 != get_space_used() ) { + while ( 0 !== get_space_used() ) { restore_current_blog(); $blog_id = self::factory()->blog->create(); switch_to_blog( $blog_id ); diff --git a/tests/phpunit/tests/multisite/site.php b/tests/phpunit/tests/multisite/site.php index 9b53df1709..2beb4ca090 100644 --- a/tests/phpunit/tests/multisite/site.php +++ b/tests/phpunit/tests/multisite/site.php @@ -166,16 +166,21 @@ if ( is_multisite() ) : // Check existence of each database table for the created site. foreach ( $wpdb->tables( 'blog', false ) as $table ) { - $suppress = $wpdb->suppress_errors(); + $suppress = $wpdb->suppress_errors(); + + // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared $table_fields = $wpdb->get_results( "DESCRIBE $prefix$table;" ); + $wpdb->suppress_errors( $suppress ); // The table should exist. $this->assertNotEmpty( $table_fields ); // And the table should not be empty, unless commentmeta, termmeta, or links. + // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared $result = $wpdb->get_results( "SELECT * FROM $prefix$table LIMIT 1" ); - if ( 'commentmeta' == $table || 'termmeta' == $table || 'links' == $table ) { + + if ( 'commentmeta' === $table || 'termmeta' === $table || 'links' === $table ) { $this->assertEmpty( $result ); } else { $this->assertNotEmpty( $result ); @@ -244,8 +249,11 @@ if ( is_multisite() ) : $prefix = $wpdb->get_blog_prefix( $blog_id ); foreach ( $wpdb->tables( 'blog', false ) as $table ) { - $suppress = $wpdb->suppress_errors(); + $suppress = $wpdb->suppress_errors(); + + // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared $table_fields = $wpdb->get_results( "DESCRIBE $prefix$table;" ); + $wpdb->suppress_errors( $suppress ); $this->assertNotEmpty( $table_fields, $prefix . $table ); } @@ -282,8 +290,11 @@ if ( is_multisite() ) : $prefix = $wpdb->get_blog_prefix( $blog_id ); foreach ( $wpdb->tables( 'blog', false ) as $table ) { - $suppress = $wpdb->suppress_errors(); + $suppress = $wpdb->suppress_errors(); + + // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared $table_fields = $wpdb->get_results( "DESCRIBE $prefix$table;" ); + $wpdb->suppress_errors( $suppress ); $this->assertEmpty( $table_fields ); } @@ -320,8 +331,11 @@ if ( is_multisite() ) : $prefix = $wpdb->get_blog_prefix( $blog_id ); foreach ( $wpdb->tables( 'blog', false ) as $table ) { - $suppress = $wpdb->suppress_errors(); + $suppress = $wpdb->suppress_errors(); + + // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared $table_fields = $wpdb->get_results( "DESCRIBE $prefix$table;" ); + $wpdb->suppress_errors( $suppress ); $this->assertNotEmpty( $table_fields, $prefix . $table ); } @@ -855,7 +869,7 @@ if ( is_multisite() ) : * the testing of the filter and for a test which does not need the database. */ function _domain_exists_cb( $exists, $domain, $path, $site_id ) { - if ( 'foo' == $domain && 'bar/' == $path ) { + if ( 'foo' === $domain && 'bar/' === $path ) { return 1234; } else { return null; diff --git a/tests/phpunit/tests/oembed/controller.php b/tests/phpunit/tests/oembed/controller.php index 2852eda2de..b726735152 100644 --- a/tests/phpunit/tests/oembed/controller.php +++ b/tests/phpunit/tests/oembed/controller.php @@ -121,7 +121,7 @@ class Test_oEmbed_Controller extends WP_UnitTestCase { ); } - if ( $url === self::UNTRUSTED_PROVIDER_URL ) { + if ( self::UNTRUSTED_PROVIDER_URL === $url ) { return array( 'response' => array( 'code' => 200, diff --git a/tests/phpunit/tests/oembed/headers.php b/tests/phpunit/tests/oembed/headers.php index 6125bf9d1f..6fc4ae6800 100644 --- a/tests/phpunit/tests/oembed/headers.php +++ b/tests/phpunit/tests/oembed/headers.php @@ -30,6 +30,6 @@ class Tests_oEmbed_HTTP_Headers extends WP_UnitTestCase { $headers = xdebug_get_headers(); - $this->assertTrue( in_array( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), $headers ) ); + $this->assertTrue( in_array( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), $headers, true ) ); } } diff --git a/tests/phpunit/tests/pomo/mo.php b/tests/phpunit/tests/pomo/mo.php index d48467c936..a3990198dd 100644 --- a/tests/phpunit/tests/pomo/mo.php +++ b/tests/phpunit/tests/pomo/mo.php @@ -178,7 +178,7 @@ class Tests_POMO_MO extends WP_UnitTestCase { } function test_overloaded_mb_functions() { - if ( ( ini_get( 'mbstring.func_overload' ) & 2 ) == 0 ) { + if ( ( ini_get( 'mbstring.func_overload' ) & 2 ) === 0 ) { $this->markTestSkipped( __METHOD__ . ' only runs when mbstring.func_overload is enabled.' ); } diff --git a/tests/phpunit/tests/pomo/pluralForms.php b/tests/phpunit/tests/pomo/pluralForms.php index 7bd9ff89e3..2cd283cf95 100644 --- a/tests/phpunit/tests/pomo/pluralForms.php +++ b/tests/phpunit/tests/pomo/pluralForms.php @@ -60,7 +60,7 @@ class PluralFormsTest extends WP_UnitTestCase { $plural_expressions = array(); foreach ( $locales as $slug => $locale ) { $plural_expression = $locale->plural_expression; - if ( $plural_expression !== 'n != 1' ) { + if ( 'n != 1' !== $plural_expression ) { $plural_expressions[] = array( $slug, $locale->nplurals, $plural_expression ); } } @@ -82,14 +82,14 @@ class PluralFormsTest extends WP_UnitTestCase { $parenthesized = self::parenthesize_plural_expression( $expression ); $old_style = tests_make_plural_form_function( $nplurals, $parenthesized ); - $pluralForms = new Plural_Forms( $expression ); + $plural_forms = new Plural_Forms( $expression ); $generated_old = array(); $generated_new = array(); foreach ( range( 0, 200 ) as $i ) { $generated_old[] = $old_style( $i ); - $generated_new[] = $pluralForms->get( $i ); + $generated_new[] = $plural_forms->get( $i ); } $this->assertSame( $generated_old, $generated_new ); @@ -151,10 +151,10 @@ class PluralFormsTest extends WP_UnitTestCase { * @dataProvider simple_provider */ public function test_simple( $expression, $expected ) { - $pluralForms = new Plural_Forms( $expression ); - $actual = array(); + $plural_forms = new Plural_Forms( $expression ); + $actual = array(); foreach ( array_keys( $expected ) as $num ) { - $actual[ $num ] = $pluralForms->get( $num ); + $actual[ $num ] = $plural_forms->get( $num ); } $this->assertSame( $expected, $actual ); @@ -212,9 +212,9 @@ class PluralFormsTest extends WP_UnitTestCase { */ public function test_exceptions( $expression, $expected_exception, $call_get ) { try { - $pluralForms = new Plural_Forms( $expression ); + $plural_forms = new Plural_Forms( $expression ); if ( $call_get ) { - $pluralForms->get( 1 ); + $plural_forms->get( 1 ); } } catch ( Exception $e ) { $this->assertEquals( $expected_exception, $e->getMessage() ); diff --git a/tests/phpunit/tests/post.php b/tests/phpunit/tests/post.php index 70d93ea355..6ef0c8449f 100644 --- a/tests/phpunit/tests/post.php +++ b/tests/phpunit/tests/post.php @@ -95,7 +95,7 @@ class Tests_Post extends WP_UnitTestCase { $this->assertEquals( 2, count( $tcache ) ); $tcache = wp_cache_get( $id, 'ctax_relationships' ); - if ( 'cpt' == $post_type ) { + if ( 'cpt' === $post_type ) { $this->assertInternalType( 'array', $tcache ); $this->assertEquals( 2, count( $tcache ) ); } else { @@ -1008,7 +1008,7 @@ class Tests_Post extends WP_UnitTestCase { */ function test_utf8mb3_post_saves_with_emoji() { global $wpdb; - $_wpdb = new wpdb_exposed_methods_for_testing(); + $_wpdb = new WpdbExposedMethodsForTesting(); if ( 'utf8' !== $_wpdb->get_col_charset( $wpdb->posts, 'post_title' ) ) { $this->markTestSkipped( 'This test is only useful with the utf8 character set' ); diff --git a/tests/phpunit/tests/post/meta.php b/tests/phpunit/tests/post/meta.php index 2344b1db8f..a79228c070 100644 --- a/tests/phpunit/tests/post/meta.php +++ b/tests/phpunit/tests/post/meta.php @@ -95,7 +95,7 @@ class Tests_Post_Meta extends WP_UnitTestCase { 'another value', ); sort( $expected ); - $this->assertTrue( in_array( get_post_meta( self::$post_id, 'nonunique', true ), $expected ) ); + $this->assertTrue( in_array( get_post_meta( self::$post_id, 'nonunique', true ), $expected, true ) ); $actual = get_post_meta( self::$post_id, 'nonunique', false ); sort( $actual ); $this->assertEquals( $expected, $actual ); diff --git a/tests/phpunit/tests/post/nav-menu.php b/tests/phpunit/tests/post/nav-menu.php index c6e86ffb3c..711a52d982 100644 --- a/tests/phpunit/tests/post/nav-menu.php +++ b/tests/phpunit/tests/post/nav-menu.php @@ -651,9 +651,9 @@ class Test_Nav_Menus extends WP_UnitTestCase { ); $tag_id = self::factory()->tag->create(); - $wpdb->query( "UPDATE $wpdb->posts SET ID=$new_id WHERE ID=$page_id" ); - $wpdb->query( "UPDATE $wpdb->terms SET term_id=$new_id WHERE term_id=$tag_id" ); - $wpdb->query( "UPDATE $wpdb->term_taxonomy SET term_id=$new_id WHERE term_id=$tag_id" ); + $wpdb->update( $wpdb->posts, array( 'ID' => $new_id ), array( 'ID' => $page_id ) ); + $wpdb->update( $wpdb->terms, array( 'term_id' => $new_id ), array( 'term_id' => $tag_id ) ); + $wpdb->update( $wpdb->term_taxonomy, array( 'term_id' => $new_id ), array( 'term_id' => $tag_id ) ); update_option( 'page_on_front', $new_id ); diff --git a/tests/phpunit/tests/post/objects.php b/tests/phpunit/tests/post/objects.php index d468e4e5c4..c2d05a555a 100644 --- a/tests/phpunit/tests/post/objects.php +++ b/tests/phpunit/tests/post/objects.php @@ -36,7 +36,7 @@ class Tests_Post_Objects extends WP_UnitTestCase { $post = get_post( $id, ARRAY_N ); $this->assertInternalType( 'array', $post ); $this->assertFalse( isset( $post['post_type'] ) ); - $this->assertTrue( in_array( 'post', $post ) ); + $this->assertTrue( in_array( 'post', $post, true ) ); $post = get_post( $id ); $post = get_post( $post, ARRAY_A ); diff --git a/tests/phpunit/tests/post/thumbnails.php b/tests/phpunit/tests/post/thumbnails.php index d47527b5d0..e8ca9e41a7 100644 --- a/tests/phpunit/tests/post/thumbnails.php +++ b/tests/phpunit/tests/post/thumbnails.php @@ -71,7 +71,7 @@ class Tests_Post_Thumbnail_Template extends WP_UnitTestCase { function test_update_post_thumbnail_cache() { set_post_thumbnail( self::$post, self::$attachment_id ); - $WP_Query = new WP_Query( + $query = new WP_Query( array( 'post_type' => 'any', 'post__in' => array( self::$post->ID ), @@ -79,11 +79,11 @@ class Tests_Post_Thumbnail_Template extends WP_UnitTestCase { ) ); - $this->assertFalse( $WP_Query->thumbnails_cached ); + $this->assertFalse( $query->thumbnails_cached ); - update_post_thumbnail_cache( $WP_Query ); + update_post_thumbnail_cache( $query ); - $this->assertTrue( $WP_Query->thumbnails_cached ); + $this->assertTrue( $query->thumbnails_cached ); } /** @@ -392,7 +392,7 @@ class Tests_Post_Thumbnail_Template extends WP_UnitTestCase { self::$different_post->ID => 'thumbnail', ); - $post = $which_post === 1 ? self::$different_post : self::$post; + $post = 1 === $which_post ? self::$different_post : self::$post; add_filter( 'post_thumbnail_size', array( $this, 'filter_post_thumbnail_size' ), 10, 2 ); diff --git a/tests/phpunit/tests/post/types.php b/tests/phpunit/tests/post/types.php index 0bfb6d103b..cdab0337f3 100644 --- a/tests/phpunit/tests/post/types.php +++ b/tests/phpunit/tests/post/types.php @@ -305,9 +305,9 @@ class Tests_Post_Types extends WP_UnitTestCase { ) ); - $this->assertInternalType( 'int', array_search( 'bar', $wp->public_query_vars ) ); + $this->assertInternalType( 'int', array_search( 'bar', $wp->public_query_vars, true ) ); $this->assertTrue( unregister_post_type( 'foo' ) ); - $this->assertFalse( array_search( 'bar', $wp->public_query_vars ) ); + $this->assertFalse( array_search( 'bar', $wp->public_query_vars, true ) ); } /** diff --git a/tests/phpunit/tests/post/wpPostType.php b/tests/phpunit/tests/post/wpPostType.php index 18bfe782cf..793e61cae9 100644 --- a/tests/phpunit/tests/post/wpPostType.php +++ b/tests/phpunit/tests/post/wpPostType.php @@ -78,7 +78,7 @@ class Tests_WP_Post_Type extends WP_UnitTestCase { ); $post_type_object->add_rewrite_rules(); - $this->assertFalse( in_array( 'foobar', $wp->public_query_vars ) ); + $this->assertFalse( in_array( 'foobar', $wp->public_query_vars, true ) ); } public function test_adds_query_var_if_public() { @@ -98,10 +98,10 @@ class Tests_WP_Post_Type extends WP_UnitTestCase { ); $post_type_object->add_rewrite_rules(); - $in_array = in_array( 'foobar', $wp->public_query_vars ); + $in_array = in_array( 'foobar', $wp->public_query_vars, true ); $post_type_object->remove_rewrite_rules(); - $in_array_after = in_array( 'foobar', $wp->public_query_vars ); + $in_array_after = in_array( 'foobar', $wp->public_query_vars, true ); $this->assertTrue( $in_array ); $this->assertFalse( $in_array_after ); @@ -128,8 +128,8 @@ class Tests_WP_Post_Type extends WP_UnitTestCase { $post_type_object->remove_rewrite_rules(); $rewrite_tags_after = $wp_rewrite->rewritecode; - $this->assertNotFalse( array_search( "%$post_type%", $rewrite_tags ) ); - $this->assertFalse( array_search( "%$post_type%", $rewrite_tags_after ) ); + $this->assertNotFalse( array_search( "%$post_type%", $rewrite_tags, true ) ); + $this->assertFalse( array_search( "%$post_type%", $rewrite_tags_after, true ) ); } public function test_register_meta_boxes() { diff --git a/tests/phpunit/tests/rest-api.php b/tests/phpunit/tests/rest-api.php index 7e72708d43..237fd71ee4 100644 --- a/tests/phpunit/tests/rest-api.php +++ b/tests/phpunit/tests/rest-api.php @@ -255,7 +255,7 @@ class Tests_REST_API extends WP_UnitTestCase { */ function test_rest_route_query_var() { rest_api_init(); - $this->assertTrue( in_array( 'rest_route', $GLOBALS['wp']->public_query_vars ) ); + $this->assertTrue( in_array( 'rest_route', $GLOBALS['wp']->public_query_vars, true ) ); } public function test_route_method() { diff --git a/tests/phpunit/tests/rest-api/rest-posts-controller.php b/tests/phpunit/tests/rest-api/rest-posts-controller.php index 13f90846ea..f03eee8e83 100644 --- a/tests/phpunit/tests/rest-api/rest-posts-controller.php +++ b/tests/phpunit/tests/rest-api/rest-posts-controller.php @@ -2491,7 +2491,7 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te } public function revoke_assign_term( $caps, $cap, $user_id, $args ) { - if ( 'assign_term' === $cap && isset( $args[0] ) && $this->forbidden_cat == $args[0] ) { + if ( 'assign_term' === $cap && isset( $args[0] ) && $this->forbidden_cat === $args[0] ) { $caps = array( 'do_not_allow' ); } return $caps; diff --git a/tests/phpunit/tests/rest-api/rest-request.php b/tests/phpunit/tests/rest-api/rest-request.php index 7d318ce999..cf3d79142c 100644 --- a/tests/phpunit/tests/rest-api/rest-request.php +++ b/tests/phpunit/tests/rest-api/rest-request.php @@ -463,8 +463,8 @@ class Tests_REST_Request extends WP_UnitTestCase { $data = $valid->get_error_data( 'rest_missing_callback_param' ); - $this->assertTrue( in_array( 'someinteger', $data['params'] ) ); - $this->assertTrue( in_array( 'someotherinteger', $data['params'] ) ); + $this->assertTrue( in_array( 'someinteger', $data['params'], true ) ); + $this->assertTrue( in_array( 'someotherinteger', $data['params'], true ) ); } public function test_has_valid_params_validate_callback() { diff --git a/tests/phpunit/tests/shortcode.php b/tests/phpunit/tests/shortcode.php index be1b1ad760..a978779c9a 100644 --- a/tests/phpunit/tests/shortcode.php +++ b/tests/phpunit/tests/shortcode.php @@ -38,7 +38,8 @@ class Tests_Shortcode extends WP_UnitTestCase { // [footag foo="bar"] function _shortcode_footag( $atts ) { - return @"foo = {$atts['foo']}"; + $foo = isset( $atts['foo'] ) ? $atts['foo'] : ''; + return "foo = $foo"; } // [bartag foo="bar"] @@ -444,7 +445,7 @@ EOF; // Filter shortcode atts in various ways function _filter_atts2( $out, $pairs, $atts ) { // If foo attribute equals "foo1", change it to be default value - if ( isset( $out['foo'] ) && 'foo1' == $out['foo'] ) { + if ( isset( $out['foo'] ) && 'foo1' === $out['foo'] ) { $out['foo'] = $pairs['foo']; } diff --git a/tests/phpunit/tests/taxonomy.php b/tests/phpunit/tests/taxonomy.php index 1286322bb1..6d30ccf778 100644 --- a/tests/phpunit/tests/taxonomy.php +++ b/tests/phpunit/tests/taxonomy.php @@ -811,9 +811,9 @@ class Tests_Taxonomy extends WP_UnitTestCase { register_taxonomy( 'foo', 'post', array( 'query_var' => 'bar' ) ); - $this->assertInternalType( 'int', array_search( 'bar', $wp->public_query_vars ) ); + $this->assertInternalType( 'int', array_search( 'bar', $wp->public_query_vars, true ) ); $this->assertTrue( unregister_taxonomy( 'foo' ) ); - $this->assertFalse( array_search( 'bar', $wp->public_query_vars ) ); + $this->assertFalse( array_search( 'bar', $wp->public_query_vars, true ) ); } /** diff --git a/tests/phpunit/tests/term/cache.php b/tests/phpunit/tests/term/cache.php index f53432918d..bfebe9338e 100644 --- a/tests/phpunit/tests/term/cache.php +++ b/tests/phpunit/tests/term/cache.php @@ -90,7 +90,7 @@ class Tests_Term_Cache extends WP_UnitTestCase { $this->assertEquals( $children, count( $hierarchy, COUNT_RECURSIVE ) - count( $hierarchy ) ); } - if ( $i % 3 === 0 ) { + if ( 0 === ( $i % 3 ) ) { $step = 1; } else { $step++; diff --git a/tests/phpunit/tests/term/getTerms.php b/tests/phpunit/tests/term/getTerms.php index b2a0965306..b40f0d64a3 100644 --- a/tests/phpunit/tests/term/getTerms.php +++ b/tests/phpunit/tests/term/getTerms.php @@ -2474,9 +2474,9 @@ class Tests_Term_getTerms extends WP_UnitTestCase { $this->assertEqualSets( array( $t1, $t2, $t3 ), wp_list_pluck( $found, 'term_id' ) ); foreach ( $found as $f ) { - if ( $t1 == $f->term_id ) { + if ( $t1 === $f->term_id ) { $this->assertSame( 3, $f->count ); - } elseif ( $t2 == $f->term_id ) { + } elseif ( $t2 === $f->term_id ) { $this->assertSame( 2, $f->count ); } else { $this->assertSame( 1, $f->count ); @@ -2547,9 +2547,9 @@ class Tests_Term_getTerms extends WP_UnitTestCase { $this->assertEqualSets( array( $t1, $t2, $t3 ), wp_list_pluck( $found, 'term_id' ) ); foreach ( $found as $f ) { - if ( $t1 == $f->term_id ) { + if ( $t1 === $f->term_id ) { $this->assertEquals( 1, $f->count ); - } elseif ( $t2 == $f->term_id ) { + } elseif ( $t2 === $f->term_id ) { $this->assertEquals( 2, $f->count ); } else { $this->assertEquals( 1, $f->count ); diff --git a/tests/phpunit/tests/term/wpInsertTerm.php b/tests/phpunit/tests/term/wpInsertTerm.php index 08f5dabc00..160bbab62e 100644 --- a/tests/phpunit/tests/term/wpInsertTerm.php +++ b/tests/phpunit/tests/term/wpInsertTerm.php @@ -822,7 +822,7 @@ class Tests_Term_WpInsertTerm extends WP_UnitTestCase { $cached_children = get_option( 'wptests_tax_children' ); $this->assertNotEmpty( $cached_children[ $t ] ); - $this->assertTrue( in_array( $found['term_id'], $cached_children[ $t ] ) ); + $this->assertTrue( in_array( $found['term_id'], $cached_children[ $t ], true ) ); } /** diff --git a/tests/phpunit/tests/term/wpTaxonomy.php b/tests/phpunit/tests/term/wpTaxonomy.php index 94bc882cce..3f646fd5ba 100644 --- a/tests/phpunit/tests/term/wpTaxonomy.php +++ b/tests/phpunit/tests/term/wpTaxonomy.php @@ -22,7 +22,7 @@ class Tests_WP_Taxonomy extends WP_UnitTestCase { $taxonomy_object = new WP_Taxonomy( $taxonomy, 'post' ); $taxonomy_object->add_rewrite_rules(); - $this->assertFalse( in_array( 'foobar', $wp->public_query_vars ) ); + $this->assertFalse( in_array( 'foobar', $wp->public_query_vars, true ) ); } public function test_adds_query_var_if_public() { @@ -43,10 +43,10 @@ class Tests_WP_Taxonomy extends WP_UnitTestCase { ); $taxonomy_object->add_rewrite_rules(); - $in_array = in_array( 'foobar', $wp->public_query_vars ); + $in_array = in_array( 'foobar', $wp->public_query_vars, true ); $taxonomy_object->remove_rewrite_rules(); - $in_array_after = in_array( 'foobar', $wp->public_query_vars ); + $in_array_after = in_array( 'foobar', $wp->public_query_vars, true ); $this->assertTrue( $in_array ); $this->assertFalse( $in_array_after ); @@ -74,8 +74,8 @@ class Tests_WP_Taxonomy extends WP_UnitTestCase { $taxonomy_object->remove_rewrite_rules(); $rewrite_tags_after = $wp_rewrite->rewritecode; - $this->assertNotFalse( array_search( "%$taxonomy%", $rewrite_tags ) ); - $this->assertFalse( array_search( "%$taxonomy%", $rewrite_tags_after ) ); + $this->assertNotFalse( array_search( "%$taxonomy%", $rewrite_tags, true ) ); + $this->assertFalse( array_search( "%$taxonomy%", $rewrite_tags_after, true ) ); } public function test_adds_ajax_callback() { diff --git a/tests/phpunit/tests/term/wpUpdateTerm.php b/tests/phpunit/tests/term/wpUpdateTerm.php index d9c4f60e46..5de6d83c59 100644 --- a/tests/phpunit/tests/term/wpUpdateTerm.php +++ b/tests/phpunit/tests/term/wpUpdateTerm.php @@ -685,7 +685,7 @@ class Tests_Term_WpUpdateTerm extends WP_UnitTestCase { $cached_children = get_option( 'wptests_tax_children' ); $this->assertNotEmpty( $cached_children[ $t2 ] ); - $this->assertTrue( in_array( $found['term_id'], $cached_children[ $t2 ] ) ); + $this->assertTrue( in_array( $found['term_id'], $cached_children[ $t2 ], true ) ); } /** diff --git a/tests/phpunit/tests/theme.php b/tests/phpunit/tests/theme.php index bf3ec670e5..cd871a7d28 100644 --- a/tests/phpunit/tests/theme.php +++ b/tests/phpunit/tests/theme.php @@ -243,7 +243,7 @@ class Tests_Theme extends WP_UnitTestCase { for ( $i = 0; $i < 3; $i++ ) { foreach ( $themes as $name => $theme ) { // switch to this theme - if ( $i === 2 ) { + if ( 2 === $i ) { switch_theme( $theme['Template'], $theme['Stylesheet'] ); } else { switch_theme( $theme['Stylesheet'] ); diff --git a/tests/phpunit/tests/theme/support.php b/tests/phpunit/tests/theme/support.php index f71760ed31..86561a5c9b 100644 --- a/tests/phpunit/tests/theme/support.php +++ b/tests/phpunit/tests/theme/support.php @@ -142,7 +142,7 @@ class Tests_Theme_Support extends WP_UnitTestCase { } function supports_foobar( $yesno, $args, $feature ) { - if ( $args[0] == $feature[0] ) { + if ( $args[0] === $feature[0] ) { return true; } return false; diff --git a/tests/phpunit/tests/theme/themeDir.php b/tests/phpunit/tests/theme/themeDir.php index 2cab375b1a..51e5046bae 100644 --- a/tests/phpunit/tests/theme/themeDir.php +++ b/tests/phpunit/tests/theme/themeDir.php @@ -145,7 +145,7 @@ class Tests_Theme_ThemeDir extends WP_UnitTestCase { // Ignore themes in the default /themes directory. foreach ( $themes as $theme_name => $theme ) { - if ( $theme->get_theme_root() != $this->theme_root ) { + if ( $theme->get_theme_root() !== $this->theme_root ) { unset( $themes[ $theme_name ] ); } } @@ -209,7 +209,7 @@ class Tests_Theme_ThemeDir extends WP_UnitTestCase { $this->assertFalse( empty( $theme ) ); $templates = $theme['Template Files']; - $this->assertTrue( in_array( $this->theme_root . '/page-templates/template-top-level.php', $templates ) ); + $this->assertTrue( in_array( $this->theme_root . '/page-templates/template-top-level.php', $templates, true ) ); } /** diff --git a/tests/phpunit/tests/user.php b/tests/phpunit/tests/user.php index 644adf58d0..13824009b6 100644 --- a/tests/phpunit/tests/user.php +++ b/tests/phpunit/tests/user.php @@ -81,7 +81,7 @@ class Tests_User extends WP_UnitTestCase { $found = array(); foreach ( $user_list as $user ) { // only include the users we just created - there might be some others that existed previously - if ( in_array( $user->ID, $nusers ) ) { + if ( in_array( $user->ID, $nusers, true ) ) { $found[] = $user->ID; } } @@ -161,7 +161,7 @@ class Tests_User extends WP_UnitTestCase { // for reasons unclear, the resulting array is indexed numerically; meta keys are not included anywhere. // so we'll just check to make sure our values are included somewhere. foreach ( $vals as $k => $v ) { - $this->assertTrue( isset( $out[ $k ] ) && $out[ $k ][0] == $v ); + $this->assertTrue( isset( $out[ $k ] ) && $out[ $k ][0] === $v ); } // delete one key and check again $keys = array_keys( $vals ); @@ -170,10 +170,10 @@ class Tests_User extends WP_UnitTestCase { $out = get_user_meta( self::$author_id ); // make sure that key is excluded from the results foreach ( $vals as $k => $v ) { - if ( $k == $key_to_delete ) { + if ( $k === $key_to_delete ) { $this->assertFalse( isset( $out[ $k ] ) ); } else { - $this->assertTrue( isset( $out[ $k ] ) && $out[ $k ][0] == $v ); + $this->assertTrue( isset( $out[ $k ] ) && $out[ $k ][0] === $v ); } } } @@ -599,7 +599,7 @@ class Tests_User extends WP_UnitTestCase { $this->assertWPError( $id2 ); } - @update_user_meta( $id2, 'key', 'value' ); + update_user_meta( $id2, 'key', 'value' ); $metas = array_keys( get_user_meta( 1 ) ); $this->assertNotContains( 'key', $metas ); @@ -1022,7 +1022,7 @@ class Tests_User extends WP_UnitTestCase { ) ); - $this->assertTrue( in_array( self::$contrib_id, $users ) ); + $this->assertTrue( in_array( (string) self::$contrib_id, $users, true ) ); } public function test_search_users_url() { @@ -1033,7 +1033,7 @@ class Tests_User extends WP_UnitTestCase { ) ); - $this->assertTrue( in_array( self::$contrib_id, $users ) ); + $this->assertTrue( in_array( (string) self::$contrib_id, $users, true ) ); } public function test_search_users_email() { @@ -1044,7 +1044,7 @@ class Tests_User extends WP_UnitTestCase { ) ); - $this->assertTrue( in_array( self::$contrib_id, $users ) ); + $this->assertTrue( in_array( (string) self::$contrib_id, $users, true ) ); } public function test_search_users_nicename() { @@ -1055,7 +1055,7 @@ class Tests_User extends WP_UnitTestCase { ) ); - $this->assertTrue( in_array( self::$contrib_id, $users ) ); + $this->assertTrue( in_array( (string) self::$contrib_id, $users, true ) ); } public function test_search_users_display_name() { @@ -1066,7 +1066,7 @@ class Tests_User extends WP_UnitTestCase { ) ); - $this->assertTrue( in_array( self::$contrib_id, $users ) ); + $this->assertTrue( in_array( (string) self::$contrib_id, $users, true ) ); } /** @@ -1201,8 +1201,8 @@ class Tests_User extends WP_UnitTestCase { * post author `blackburn@battlefield3.com` and and site admin `admin@example.org`. */ if ( ! empty( $GLOBALS['phpmailer']->mock_sent ) ) { - $was_admin_email_sent = ( isset( $GLOBALS['phpmailer']->mock_sent[0] ) && WP_TESTS_EMAIL == $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0] ); - $was_user_email_sent = ( isset( $GLOBALS['phpmailer']->mock_sent[1] ) && 'blackburn@battlefield3.com' == $GLOBALS['phpmailer']->mock_sent[1]['to'][0][0] ); + $was_admin_email_sent = ( isset( $GLOBALS['phpmailer']->mock_sent[0] ) && WP_TESTS_EMAIL === $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0] ); + $was_user_email_sent = ( isset( $GLOBALS['phpmailer']->mock_sent[1] ) && 'blackburn@battlefield3.com' === $GLOBALS['phpmailer']->mock_sent[1]['to'][0][0] ); } $this->assertTrue( $was_admin_email_sent ); @@ -1226,8 +1226,8 @@ class Tests_User extends WP_UnitTestCase { * post author `blackburn@battlefield3.com` and and site admin `admin@example.org`. */ if ( ! empty( $GLOBALS['phpmailer']->mock_sent ) ) { - $was_admin_email_sent = ( isset( $GLOBALS['phpmailer']->mock_sent[0] ) && WP_TESTS_EMAIL == $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0] ); - $was_user_email_sent = ( isset( $GLOBALS['phpmailer']->mock_sent[1] ) && 'blackburn@battlefield3.com' == $GLOBALS['phpmailer']->mock_sent[1]['to'][0][0] ); + $was_admin_email_sent = ( isset( $GLOBALS['phpmailer']->mock_sent[0] ) && WP_TESTS_EMAIL === $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0] ); + $was_user_email_sent = ( isset( $GLOBALS['phpmailer']->mock_sent[1] ) && 'blackburn@battlefield3.com' === $GLOBALS['phpmailer']->mock_sent[1]['to'][0][0] ); } $this->assertTrue( $was_admin_email_sent ); @@ -1465,7 +1465,7 @@ class Tests_User extends WP_UnitTestCase { do_action( 'personal_options_update' ); if ( ! empty( $GLOBALS['phpmailer']->mock_sent ) ) { - $was_confirmation_email_sent = ( isset( $GLOBALS['phpmailer']->mock_sent[0] ) && 'after@example.com' == $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0] ); + $was_confirmation_email_sent = ( isset( $GLOBALS['phpmailer']->mock_sent[0] ) && 'after@example.com' === $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0] ); } // A confirmation email is sent. @@ -1502,7 +1502,7 @@ class Tests_User extends WP_UnitTestCase { do_action( 'personal_options_update' ); if ( ! empty( $GLOBALS['phpmailer']->mock_sent ) ) { - $was_confirmation_email_sent = ( isset( $GLOBALS['phpmailer']->mock_sent[0] ) && 'after@example.com' == $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0] ); + $was_confirmation_email_sent = ( isset( $GLOBALS['phpmailer']->mock_sent[0] ) && 'after@example.com' === $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0] ); } // No confirmation email is sent. diff --git a/tests/phpunit/tests/user/capabilities.php b/tests/phpunit/tests/user/capabilities.php index a0446f17e4..d2a119163b 100644 --- a/tests/phpunit/tests/user/capabilities.php +++ b/tests/phpunit/tests/user/capabilities.php @@ -1546,7 +1546,7 @@ class Tests_User_Capabilities extends WP_UnitTestCase { function _nullify_current_user() { // Prevents fatal errors in ::tearDown()'s and other uses of restore_current_blog() $function_stack = wp_debug_backtrace_summary( null, 0, false ); - if ( in_array( 'restore_current_blog', $function_stack ) ) { + if ( in_array( 'restore_current_blog', $function_stack, true ) ) { return; } $GLOBALS['current_user'] = null; diff --git a/tests/phpunit/tests/user/query.php b/tests/phpunit/tests/user/query.php index 1330d8b5c9..c094360ebc 100644 --- a/tests/phpunit/tests/user/query.php +++ b/tests/phpunit/tests/user/query.php @@ -53,7 +53,9 @@ class Tests_User_Query extends WP_UnitTestCase { $users = new WP_User_Query(); $this->assertEquals( '', $users->get( 'fields' ) ); - $this->assertEquals( '', @$users->query_vars['fields'] ); + if ( isset( $users->query_vars['fields'] ) ) { + $this->assertEquals( '', $users->query_vars['fields'] ); + } $users->set( 'fields', 'all' ); @@ -1136,11 +1138,11 @@ class Tests_User_Query extends WP_UnitTestCase { ) ); - $foundCount = count( $q->get_results() ); - $expectedCount = 10; // 13 total users minus 3 from query + $found_count = count( $q->get_results() ); + $expected_count = 10; // 13 total users minus 3 from query $this->assertContains( "AND user_nicename NOT IN ( 'peter','paul','mary' )", $q->query_where ); - $this->assertEquals( $expectedCount, $foundCount ); + $this->assertEquals( $expected_count, $found_count ); } /** @@ -1237,11 +1239,11 @@ class Tests_User_Query extends WP_UnitTestCase { ) ); - $foundCount = count( $q->get_results() ); - $expectedCount = 10; // 13 total users minus 3 from query + $found_count = count( $q->get_results() ); + $expected_count = 10; // 13 total users minus 3 from query $this->assertContains( "AND user_login NOT IN ( '$user_login1','$user_login2','$user_login3' )", $q->query_where ); - $this->assertEquals( $expectedCount, $foundCount ); + $this->assertEquals( $expected_count, $found_count ); } /** diff --git a/tests/phpunit/tests/widgets.php b/tests/phpunit/tests/widgets.php index d2160f786f..4d404100f6 100644 --- a/tests/phpunit/tests/widgets.php +++ b/tests/phpunit/tests/widgets.php @@ -150,7 +150,7 @@ class Tests_Widgets extends WP_UnitTestCase { $names = wp_list_pluck( $wp_registered_sidebars, 'name' ); for ( $i = 1; $i <= $num; $i++ ) { - if ( in_array( "$id_base $i", $names ) ) { + if ( in_array( "$id_base $i", $names, true ) ) { $result[] = true; } } diff --git a/tests/phpunit/tests/wp.php b/tests/phpunit/tests/wp.php index 218c087c05..cdb3f79525 100644 --- a/tests/phpunit/tests/wp.php +++ b/tests/phpunit/tests/wp.php @@ -22,15 +22,15 @@ class Tests_WP extends WP_UnitTestCase { $this->wp->add_query_var( 'test' ); $this->assertSame( $public_qv_count + 2, count( $this->wp->public_query_vars ) ); - $this->assertTrue( in_array( 'test', $this->wp->public_query_vars ) ); - $this->assertTrue( in_array( 'test2', $this->wp->public_query_vars ) ); + $this->assertTrue( in_array( 'test', $this->wp->public_query_vars, true ) ); + $this->assertTrue( in_array( 'test2', $this->wp->public_query_vars, true ) ); } public function test_remove_query_var() { $public_qv_count = count( $this->wp->public_query_vars ); $this->wp->add_query_var( 'test' ); - $this->assertTrue( in_array( 'test', $this->wp->public_query_vars ) ); + $this->assertTrue( in_array( 'test', $this->wp->public_query_vars, true ) ); $this->wp->remove_query_var( 'test' ); $this->assertSame( $public_qv_count, count( $this->wp->public_query_vars ) ); diff --git a/tests/phpunit/tests/xmlrpc/mw/getRecentPosts.php b/tests/phpunit/tests/xmlrpc/mw/getRecentPosts.php index 58ebe25d58..a976ffafa2 100644 --- a/tests/phpunit/tests/xmlrpc/mw/getRecentPosts.php +++ b/tests/phpunit/tests/xmlrpc/mw/getRecentPosts.php @@ -109,7 +109,7 @@ class Tests_XMLRPC_mw_getRecentPosts extends WP_XMLRPC_UnitTestCase { $this->assertInternalType( 'string', $result['wp_post_thumbnail'] ); $this->assertStringMatchesFormat( '%d', $result['wp_post_thumbnail'] ); - if ( ! empty( $result['wp_post_thumbnail'] ) || $result['postid'] == self::$post_id ) { + if ( ! empty( $result['wp_post_thumbnail'] ) || $result['postid'] === self::$post_id ) { $attachment_id = get_post_meta( $result['postid'], '_thumbnail_id', true ); $this->assertEquals( $attachment_id, $result['wp_post_thumbnail'] ); diff --git a/tests/phpunit/tests/xmlrpc/wp/editPost.php b/tests/phpunit/tests/xmlrpc/wp/editPost.php index 7e69bf77c2..920dd4c51b 100644 --- a/tests/phpunit/tests/xmlrpc/wp/editPost.php +++ b/tests/phpunit/tests/xmlrpc/wp/editPost.php @@ -445,7 +445,7 @@ class Tests_XMLRPC_wp_editPost extends WP_XMLRPC_UnitTestCase { $this->assertEquals( 1, count( get_post_meta( $post_id, 'enclosure' ) ) ); // For good measure, check that the expected value is in the array - $this->assertTrue( in_array( $enclosure_string, get_post_meta( $post_id, 'enclosure' ) ) ); + $this->assertTrue( in_array( $enclosure_string, get_post_meta( $post_id, 'enclosure' ), true ) ); // Attempt to add a brand new enclosure via XML-RPC $this->myxmlrpcserver->add_enclosure_if_new( $post_id, $new_enclosure ); @@ -455,10 +455,10 @@ class Tests_XMLRPC_wp_editPost extends WP_XMLRPC_UnitTestCase { // Check that the new enclosure is in the enclosure meta $new_enclosure_string = "{$new_enclosure['url']}\n{$new_enclosure['length']}\n{$new_enclosure['type']}\n"; - $this->assertTrue( in_array( $new_enclosure_string, get_post_meta( $post_id, 'enclosure' ) ) ); + $this->assertTrue( in_array( $new_enclosure_string, get_post_meta( $post_id, 'enclosure' ), true ) ); // Check that the old enclosure is in the enclosure meta - $this->assertTrue( in_array( $enclosure_string, get_post_meta( $post_id, 'enclosure' ) ) ); + $this->assertTrue( in_array( $enclosure_string, get_post_meta( $post_id, 'enclosure' ), true ) ); } /** diff --git a/tests/phpunit/tests/xmlrpc/wp/getPages.php b/tests/phpunit/tests/xmlrpc/wp/getPages.php index 76c9f360cb..40da0ea891 100644 --- a/tests/phpunit/tests/xmlrpc/wp/getPages.php +++ b/tests/phpunit/tests/xmlrpc/wp/getPages.php @@ -55,8 +55,8 @@ class Tests_XMLRPC_wp_getPages extends WP_XMLRPC_UnitTestCase { } function remove_editor_edit_page_cap( $caps, $cap, $user_id, $args ) { - if ( in_array( $cap, array( 'edit_page', 'edit_others_pages' ) ) ) { - if ( $user_id == self::$editor_id && $args[0] == self::$post_id ) { + if ( in_array( $cap, array( 'edit_page', 'edit_others_pages' ), true ) ) { + if ( $user_id === self::$editor_id && $args[0] === self::$post_id ) { return array( false ); } } @@ -78,7 +78,7 @@ class Tests_XMLRPC_wp_getPages extends WP_XMLRPC_UnitTestCase { // WP#20629 $this->assertNotIXRError( $result ); - if ( $result['page_id'] == self::$post_id ) { + if ( $result['page_id'] === self::$post_id ) { $found_incapable = true; break; } diff --git a/tests/phpunit/tests/xmlrpc/wp/getTerms.php b/tests/phpunit/tests/xmlrpc/wp/getTerms.php index 2432fecf53..477bed7195 100644 --- a/tests/phpunit/tests/xmlrpc/wp/getTerms.php +++ b/tests/phpunit/tests/xmlrpc/wp/getTerms.php @@ -121,9 +121,9 @@ class Tests_XMLRPC_wp_getTerms extends WP_XMLRPC_UnitTestCase { $this->assertNotEquals( 0, count( $results ) ); foreach ( $results as $term ) { - if ( $term['term_id'] == $cat1 ) { + if ( $term['term_id'] === $cat1 ) { break; // found cat1 first as expected - } elseif ( $term['term_id'] == $cat2 ) { + } elseif ( $term['term_id'] === $cat2 ) { $this->assertFalse( false, 'Incorrect category ordering.' ); } } diff --git a/tests/phpunit/wp-mail-real-test.php b/tests/phpunit/wp-mail-real-test.php index 55bd090773..67da30ef86 100644 --- a/tests/phpunit/wp-mail-real-test.php +++ b/tests/phpunit/wp-mail-real-test.php @@ -53,7 +53,7 @@ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); wp_install( WP_BLOG_TITLE, WP_USER_NAME, WP_USER_EMAIL, true ); // make sure we're installed -assert( true == is_blog_installed() ); +assert( true === is_blog_installed() ); // phpcs:ignore Generic.NamingConventions.UpperCaseConstantName.ConstantNotUpperCase define( 'PHPUnit_MAIN_METHOD', false );