Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/tests-unit-php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ jobs:
composer-options: '--prefer-dist --no-progress --no-interaction --no-scripts'

- name: Update PHPUnit
if: ${{ matrix.php == 'nightly' }}
run: |
echo "Installing latest version of PHPUnit"
composer update --ignore-platform-reqs --no-interaction --no-scripts yoast/phpunit-polyfills --with-dependencies
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"swissspidy/phpstan-no-private": "^1.0.0",
"szepeviktor/phpstan-wordpress": "^2.0.0",
"wp-coding-standards/wpcs": "^3.0.0",
"yoast/phpunit-polyfills": "2.0.5 as 1.1.0",
"yoast/wp-test-utils": "^1.0.0"
},
"suggest": {
Expand Down
344 changes: 211 additions & 133 deletions composer.lock

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions phpunit-integration-multisite.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
convertDeprecationsToExceptions="true"
displayDetailsOnPhpunitDeprecations="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerWarnings="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.2/phpunit.xsd"
>
<php>
Expand Down
6 changes: 6 additions & 0 deletions phpunit-integration.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
convertDeprecationsToExceptions="true"
displayDetailsOnPhpunitDeprecations="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerWarnings="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.2/phpunit.xsd"
>
<php>
Expand Down
6 changes: 0 additions & 6 deletions tests/phpunit/integration/includes/Kses_Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@ protected function kses_int(): void {
* Remove filters and reset kses by calling kses init.
*/
protected function kses_remove_filters(): void {
if ( ! current_user_can( 'unfiltered_html' ) ) {
remove_filter( 'safe_style_css', [ $this->kses, 'filter_safe_style_css' ] );
remove_filter( 'wp_kses_allowed_html', [ $this->kses, 'filter_kses_allowed_html' ] );
remove_filter( 'content_save_pre', [ $this->kses, 'filter_content_save_pre_before_kses' ], 0 );
remove_filter( 'content_save_pre', [ $this->kses, 'filter_content_save_pre_after_kses' ], 20 );
}
kses_init();
}
}
8 changes: 8 additions & 0 deletions tests/phpunit/integration/includes/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ public function tear_down(): void {
parent::tear_down();
}

/**
* Temporary workaround to allow the tests to run on PHPUnit 10.
*
* @link https://core.trac.wordpress.org/ticket/59486
*/
public function expectDeprecated(): void {
}

/**
* @param mixed $data Product data.
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/integration/tests/Integrations/AMP.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function test_filter_supportable_post_types(): void {
/**
* @return array<string, array{0: array<int, mixed>, 1: bool}>
*/
public function data_test_filter_amp_to_amp_linking_element_excluded(): array {
public static function data_test_filter_amp_to_amp_linking_element_excluded(): array {
$doc = new DOMDocument( '1.0', 'utf-8' );

$anchor = $doc->createElement( 'a' );
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/integration/tests/Integrations/Jetpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public function filter_wp_get_attachment_metadata( $value, int $object_id, strin
/**
* @return array<int|string, array<int|float|string>>
*/
public function data_format_milliseconds(): array {
public static function data_format_milliseconds(): array {
return [
'5000' => [
5000,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ public function test_validate_url_should_validate( string $url, $cb_safe_ports =
*
* @return array<string, array{url: string, cb_safe_ports?: callable}>
*/
public function data_validate_url_should_validate(): array {
public static function data_validate_url_should_validate(): array {
return [
'no port specified' => [
'url' => 'http://example.com/caniload.php',
Expand All @@ -486,7 +486,7 @@ public function data_validate_url_should_validate(): array {
],
'a port considered safe by filter' => [
'url' => 'https://example.com:81/caniload.php',
'cb_safe_ports' => [ $this, 'callback_custom_safe_ports' ],
'cb_safe_ports' => [ self::class, 'callback_custom_safe_ports' ],
],
];
}
Expand Down Expand Up @@ -549,7 +549,7 @@ public function test_validate_url_should_not_validate( string $url, $cb_safe_por
*
* @return array<string, array{url: string, cb_safe_ports?: callable}>
*/
public function data_validate_url_should_not_validate(): array {
public static function data_validate_url_should_not_validate(): array {
return [
'url as string 0' => [
'url' => '0',
Expand Down Expand Up @@ -589,26 +589,26 @@ public function data_validate_url_should_not_validate(): array {
],
'a port not considered safe by filter' => [
'url' => 'https://example.com:82/caniload.php',
'cb_safe_ports' => [ $this, 'callback_custom_safe_ports' ],
'cb_safe_ports' => [ self::class, 'callback_custom_safe_ports' ],
],
'all safe ports removed by filter' => [
'url' => 'https://example.com:81/caniload.php',
'cb_safe_ports' => [ $this, 'callback_remove_safe_ports' ],
'cb_safe_ports' => [ self::class, 'callback_remove_safe_ports' ],
],
];
}

/**
* @return array<int>
*/
public function callback_custom_safe_ports(): array {
public static function callback_custom_safe_ports(): array {
return [ 81, 444, 8081 ];
}

/**
* @return array<int>
*/
public function callback_remove_safe_ports(): array {
public static function callback_remove_safe_ports(): array {
return [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ public function test_instagram_urls( string $url, array $expected, int $request_
/**
* @return array<string,array{url: string, expected: array<string, string>, request_count: int}>
*/
public function data_instagram_urls(): array {
public static function data_instagram_urls(): array {
return [
'Instagram profile url' => [
'url' => self::URL_INSTAGRAM,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public function test_get_items_hierarchical( bool $hierarchical ): void {
/**
* @return array<string, bool[]>
*/
public function data_show_ui(): array {
public static function data_show_ui(): array {
return [
'true' => [ true ],
'false' => [ false ],
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/integration/tests/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function test_get_setting_uses_type( string $name, array $args, $value, $
/**
* @return array<string, array<string, mixed>>
*/
public function data_test_types(): array {
public static function data_test_types(): array {
return [
'array from string' => [
'name' => 'array_type',
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/integration/tests/Shopping/Shopify_Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public function test_get_search_empty_search_response(): void {
*
* @dataProvider data_test_get_search_sort_by_query
*/
public function data_test_get_search_sort_by_query(): array {
public static function data_test_get_search_sort_by_query(): array {
return [
'Default search' => [
[ 'some search term', 1, 100, 'date', '' ],
Expand Down Expand Up @@ -397,7 +397,7 @@ public function test_get_search_sort_by_query( array $args, array $expected ): v
*
* @dataProvider data_test_get_search_extensions_code_response
*/
public function data_test_get_search_extensions_code_response(): array {
public static function data_test_get_search_extensions_code_response(): array {
return [
'THROTTLED' => [
'throttled',
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/integration/tests/Story_Revisions.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function test_revisions_to_keep( $num, int $expected ): void {
/**
* @return array<array{num: mixed, expected: int}>
*/
public function data_test_revisions_to_keep(): array {
public static function data_test_revisions_to_keep(): array {
return [
[
'num' => 0,
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/unit/tests/AMP/Story_Sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ public function test_transform_html_start_tag(): void {
/**
* @return array<string, array<int, string>>
*/
public function data_test_transform_a_tags(): array {
public static function data_test_transform_a_tags(): array {
return [
'Link without rel or target attribute' => [
'<html><head></head><body><a href="https://www.google.com">Google</a></body></html>',
Expand Down Expand Up @@ -793,7 +793,7 @@ public function test_sanitize_title_and_meta_description( string $source, string
/**
* @return array<string, array<int, string>>
*/
public function data_test_sanitize_title_and_meta_description(): array {
public static function data_test_sanitize_title_and_meta_description(): array {
return [
'Both title tag and description present' => [
'<html amp="" lang="en-US"><head><meta charset="utf-8"><title>Existing title</title><meta name="description" content="Existing description"></head><body></body></html>',
Expand Down
Loading