Skip to content

Commit

Permalink
Merge pull request #696 from lucatume/v4-isse-692
Browse files Browse the repository at this point in the history
Avoid warnings on PHPUnit gte 10
  • Loading branch information
lucatume authored Feb 9, 2024
2 parents 6dba0de + 371ccb0 commit e85c4ce
Show file tree
Hide file tree
Showing 21 changed files with 247 additions and 110 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [unreleased] Unreleased

### Fixed

- PHPUnit version 10+ warnings (#692)

### Changed

- Updated Core PHPUnit test code from `wordpress/wordpress-develop`.
- Update SQLite plugin from `sqlite-database-integration` plugin.

## [4.0.18] 2024-01-23;

- Improve messaging and documentation around initialization and setup.
Expand Down
3 changes: 2 additions & 1 deletion bin/namespace_global_class_names.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
use PhpParser\NodeVisitor\NameResolver;
use PhpParser\NodeVisitorAbstract;
use PhpParser\ParserFactory;
use PhpParser\PhpVersion;

require_once dirname(__DIR__) . '/vendor/autoload.php';

// Build a PHP parser using nikic/php-parser
$parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP5);
$parser = (new ParserFactory())->createForVersion(PHPVersion::fromComponents(8, 0));

// Build an iterator over all the .php files in the includes directory
$files = new RegexIterator(
Expand Down
10 changes: 8 additions & 2 deletions bin/update_core_phpunit_includes
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ set -eux

script_dir=$(dirname "$0")
root_dir=$(cd "$script_dir/.." && pwd)
includes_src="https://github.com/WordPress/wordpress-develop/branches/trunk/tests/phpunit/includes"

rm -rf "${root_dir}"/includes/core-phpunit/includes &&
rm -rf "${root_dir}"/includes/core-phpunit/wordpress-develop &&
mkdir -p "${root_dir}"/includes/core-phpunit &&
cd "${root_dir}"/includes/core-phpunit &&
svn export $includes_src
git clone -n --depth=1 --filter=tree:0 https://github.com/WordPress/wordpress-develop &&
cd wordpress-develop &&
git sparse-checkout set --no-cone tests/phpunit/includes &&
git checkout &&
cd .. &&
mv wordpress-develop/tests/phpunit/includes ./includes &&
rm -rf wordpress-develop &&
git apply "${root_dir}"/config/patches/core-phpunit/includes/abstract-testcase.php.patch &&
git apply "${root_dir}"/config/patches/core-phpunit/includes/testcase-ajax.php.patch &&
git apply "${root_dir}"/config/patches/core-phpunit/includes/testcase-canonical.php.patch &&
Expand Down
16 changes: 16 additions & 0 deletions includes/core-phpunit/includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,26 @@ function _wp_rest_server_class_filter() {
* @since 5.0.0
*/
function _unhook_block_registration() {
// Block types.
require __DIR__ . '/unregister-blocks-hooks.php';
remove_action( 'init', 'register_core_block_types_from_metadata' );
remove_action( 'init', 'register_block_core_legacy_widget' );
remove_action( 'init', 'register_block_core_widget_group' );
remove_action( 'init', 'register_core_block_types_from_metadata' );

// Block binding sources.
remove_action( 'init', '_register_block_bindings_pattern_overrides_source' );
remove_action( 'init', '_register_block_bindings_post_meta_source' );
}
tests_add_filter( 'init', '_unhook_block_registration', 1000 );

/**
* After the init action has been run once, trying to re-register font collections can cause
* errors. To avoid this, unhook the font registration functions.
*
* @since 6.5.0
*/
function _unhook_font_registration() {
remove_action( 'init', '_wp_register_default_font_collections' );
}
tests_add_filter( 'init', '_unhook_font_registration', 1000 );
6 changes: 6 additions & 0 deletions includes/core-phpunit/includes/unregister-blocks-hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,9 @@
remove_action( 'init', 'register_block_core_tag_cloud' );
remove_action( 'init', 'register_block_core_template_part' );
remove_action( 'init', 'register_block_core_term_description' );

// Temporary hook removals to prevent impacting the phpunit tests timing.
remove_action( 'registered_post_type', 'block_core_navigation_link_register_post_type_variation' );
remove_action( 'registered_taxonomy', 'block_core_navigation_link_register_taxonomy_variation' );
remove_action( 'unregistered_post_type', 'block_core_navigation_link_unregister_post_type_variation' );
remove_action( 'unregistered_taxonomy', 'block_core_navigation_link_unregister_taxonomy_variation' );
5 changes: 3 additions & 2 deletions includes/sqlite-database-integration/activate.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
*/
function sqlite_plugin_activation_redirect( $plugin ) {
if ( plugin_basename( SQLITE_MAIN_FILE ) === $plugin ) {
wp_redirect( admin_url( 'options-general.php?page=sqlite-integration' ) );
exit;
if ( wp_safe_redirect( admin_url( 'options-general.php?page=sqlite-integration' ) ) ) {
exit;
}
}
}
add_action( 'activated_plugin', 'sqlite_plugin_activation_redirect' );
Expand Down
2 changes: 1 addition & 1 deletion includes/sqlite-database-integration/admin-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function sqlite_add_admin_menu() {
__( 'SQLite integration', 'sqlite-database-integration' ),
'manage_options',
'sqlite-integration',
'sqlite_integration_admin_screen',
'sqlite_integration_admin_screen'
);
}
add_action( 'admin_menu', 'sqlite_add_admin_menu' );
Expand Down
2 changes: 1 addition & 1 deletion includes/sqlite-database-integration/deactivate.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function sqlite_plugin_remove_db_file() {
// Run an action on `shutdown`, to deactivate the option in the MySQL database.
add_action(
'shutdown',
function() {
function () {
global $table_prefix;

// Get credentials for the MySQL database.
Expand Down
6 changes: 3 additions & 3 deletions includes/sqlite-database-integration/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
/**
* Plugin Name: SQLite Database Integration
* Description: SQLite database driver drop-in.
* Author: WordPress Performance Team
* Version: 2.1.2
* Requires PHP: 5.6
* Author: The WordPress Team
* Version: 2.1.6
* Requires PHP: 7.0
* Textdomain: sqlite-database-integration
*
* This feature plugin allows WordPress to use SQLite instead of MySQL as its database.
Expand Down
4 changes: 2 additions & 2 deletions includes/sqlite-database-integration/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ Contributors: wordpressdotorg, aristath
Requires at least: 6.0
Tested up to: 6.4
Requires PHP: 5.6
Stable tag: 2.1.2
Stable tag: 2.1.6
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Tags: performance, database

SQLite-integration plugin from the WordPress Performance Team.
SQLite integration plugin by the WordPress Team.

== Description ==

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function select( $db, $dbh = null ) {
*
* @return string escaped
*/
function _real_escape( $str ) {
public function _real_escape( $str ) {
return addslashes( $str );
}

Expand Down Expand Up @@ -278,7 +278,7 @@ public function query( $query ) {
}

$this->result = $this->dbh->query( $query );
$this->num_queries++;
++$this->num_queries;

if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) {
$this->queries[] = array( $query, $this->timer_stop(), $this->get_caller() );
Expand Down Expand Up @@ -349,7 +349,7 @@ public function has_cap( $db_cap ) {
* @see wpdb::db_version()
*/
public function db_version() {
return '5.5';
return '8.0';
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* This file is a port of the Lexer & Tokens_List classes from the PHPMyAdmin/sql-parser library.
* This file is a port of the Lexer & TokensList classes from the PHPMyAdmin/sql-parser library.
*
* @package wp-sqlite-integration
* @see https://github.com/phpmyadmin/sql-parser
Expand Down Expand Up @@ -33,7 +33,7 @@ class WP_SQLite_Lexer {
*
* @var string[]
*/
public static $parser_methods = array(
protected const PARSER_METHODS = array(
// It is best to put the parsers in order of their complexity
// (ascending) and their occurrence rate (descending).
//
Expand Down Expand Up @@ -77,7 +77,7 @@ class WP_SQLite_Lexer {
*
* @var string[]
*/
public $keyword_name_indicators = array(
protected const KEYWORD_NAME_INDICATORS = array(
'FROM',
'SET',
'WHERE',
Expand All @@ -89,7 +89,7 @@ class WP_SQLite_Lexer {
*
* @var string[]
*/
public $operator_name_indicators = array(
protected const OPERATOR_NAME_INDICATORS = array(
',',
'.',
);
Expand Down Expand Up @@ -1486,7 +1486,7 @@ public function lex() {
*/
$token = null;

foreach ( static::$parser_methods as $method ) {
foreach ( self::PARSER_METHODS as $method ) {
$token = $this->$method();

if ( $token ) {
Expand Down Expand Up @@ -1668,10 +1668,10 @@ private function solve_ambiguity_on_function_keywords() {
$next = $this->tokens_get_next();
if (
( WP_SQLite_Token::TYPE_KEYWORD !== $next->type
|| ! in_array( $next->value, $this->keyword_name_indicators, true )
|| ! in_array( $next->value, self::KEYWORD_NAME_INDICATORS, true )
)
&& ( WP_SQLite_Token::TYPE_OPERATOR !== $next->type
|| ! in_array( $next->value, $this->operator_name_indicators, true )
|| ! in_array( $next->value, self::OPERATOR_NAME_INDICATORS, true )
)
&& ( null !== $next->value )
) {
Expand Down Expand Up @@ -2068,7 +2068,7 @@ public function parse_number() {
} elseif (
$this->last + 1 < $this->string_length
&& '0' === $this->str[ $this->last ]
&& ( 'x' === $this->str[ $this->last + 1 ] || 'X' === $this->str[ $this->last + 1 ] )
&& 'x' === $this->str[ $this->last + 1 ]
) {
$token .= $this->str[ $this->last++ ];
$state = 2;
Expand Down Expand Up @@ -2260,7 +2260,7 @@ public function parse_symbol() {
if ( null === $str ) {
$str = $this->parse_unknown();

if ( null === $str ) {
if ( null === $str && ! ( $flags & WP_SQLite_Token::FLAG_SYMBOL_PARAMETER ) ) {
$this->error( 'Variable name was expected.', $this->str[ $this->last ], $this->last );
}
}
Expand Down Expand Up @@ -2514,15 +2514,10 @@ public static function is_separator( $str ) {
* Constructor.
*
* @param stdClass[] $tokens The initial array of tokens.
* @param int $count The count of tokens in the initial array.
*/
public function tokens( array $tokens = array(), $count = -1 ) {
if ( empty( $tokens ) ) {
return;
}

public function tokens( array $tokens = array() ) {
$this->tokens = $tokens;
$this->tokens_count = -1 === $count ? count( $tokens ) : $count;
$this->tokens_count = count( $tokens );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public function month( $field ) {
* From https://www.php.net/manual/en/datetime.format.php:
*
* n - Numeric representation of a month, without leading zeros.
* 1 through 12
* 1 through 12
*/
return intval( gmdate( 'n', strtotime( $field ) ) );
}
Expand Down Expand Up @@ -446,14 +446,14 @@ public function isnull( $field ) {
*
* As 'IF' is a reserved word for PHP, function name must be changed.
*
* @param mixed $expression the statement to be evaluated as true or false.
* @param mixed $true statement or value returned if $expression is true.
* @param mixed $false statement or value returned if $expression is false.
* @param mixed $expression The statement to be evaluated as true or false.
* @param mixed $truthy Statement or value returned if $expression is true.
* @param mixed $falsy Statement or value returned if $expression is false.
*
* @return mixed
*/
public function _if( $expression, $true, $false ) {
return ( true === $expression ) ? $true : $false;
public function _if( $expression, $truthy, $falsy ) {
return ( true === $expression ) ? $truthy : $falsy;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class WP_SQLite_Token {
*
* @var mixed|string|null
*/
public $keyword;
public $keyword = null;

/**
* The type of this token.
Expand Down Expand Up @@ -195,11 +195,10 @@ class WP_SQLite_Token {
* @param int $flags The flags of the token.
*/
public function __construct( $token, $type = 0, $flags = 0 ) {
$this->token = $token;
$this->type = $type;
$this->flags = $flags;
$this->keyword = null;
$this->value = $this->extract();
$this->token = $token;
$this->type = $type;
$this->flags = $flags;
$this->value = $this->extract();
}

/**
Expand Down Expand Up @@ -262,8 +261,8 @@ private function extract() {
case self::TYPE_NUMBER:
$ret = str_replace( '--', '', $this->token ); // e.g. ---42 === -42.
if ( $this->flags & self::FLAG_NUMBER_HEX ) {
$ret = str_replace( array( '-', '+' ), '', $this->token );
if ( $this->flags & self::FLAG_NUMBER_NEGATIVE ) {
$ret = str_replace( '-', '', $this->token );
$ret = -hexdec( $ret );
} else {
$ret = hexdec( $ret );
Expand Down
Loading

0 comments on commit e85c4ce

Please sign in to comment.