diff options
Diffstat (limited to 'tests/phpunit/includes')
-rw-r--r-- | tests/phpunit/includes/bootstrap.php | 4 | ||||
-rw-r--r-- | tests/phpunit/includes/functions.php | 2 | ||||
-rw-r--r-- | tests/phpunit/includes/install.php | 2 | ||||
-rw-r--r-- | tests/phpunit/includes/mock-fs.php | 18 | ||||
-rw-r--r-- | tests/phpunit/includes/object-cache.php | 94 | ||||
-rw-r--r-- | tests/phpunit/includes/phpunit6/compat.php | 4 | ||||
-rw-r--r-- | tests/phpunit/includes/phpunit7/speed-trap-listener.php | 30 | ||||
-rw-r--r-- | tests/phpunit/includes/speed-trap-listener.php | 30 | ||||
-rw-r--r-- | tests/phpunit/includes/trac.php | 2 | ||||
-rw-r--r-- | tests/phpunit/includes/utils.php | 17 | ||||
-rw-r--r-- | tests/phpunit/includes/wp-profiler.php | 14 |
11 files changed, 113 insertions, 104 deletions
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; |