Skip to content

Commit

Permalink
Closes #4896 Update test suite (#4903)
Browse files Browse the repository at this point in the history
Update our test suite to be cross-compatible with WP and PHPUnit versions
  • Loading branch information
remyperona authored Apr 12, 2022
1 parent 63f6492 commit 8c603e2
Show file tree
Hide file tree
Showing 249 changed files with 1,312 additions and 1,309 deletions.
80 changes: 0 additions & 80 deletions .github/workflows/test_php8.yml

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/test_wprocket.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:
runs-on: ${{ matrix.operating-system }}

strategy:
fail-fast: false
fail-fast: true
matrix:
operating-system: [ubuntu-latest]
php-versions: ['7.3', '7.4']
php-versions: ['7.3', '7.4', '8.0']
wp-versions: ['latest']

name: WP ${{ matrix.wp-versions }} with PHP ${{ matrix.php-versions }} on ${{ matrix.operating-system }}.
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/test_wprocket_legacy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ${{ matrix.operating-system }}

strategy:
fail-fast: false
fail-fast: true
matrix:
operating-system: [ubuntu-latest]
php-versions: ['7.1', '7.2']
Expand Down Expand Up @@ -71,6 +71,9 @@ jobs:
- name: Remove unmet dependencies by legacy versions
run: composer remove --dev --no-scripts phpstan/phpstan szepeviktor/phpstan-wordpress coenjacobs/mozart

- name: Require PHPUnit 7.5 for WP compatibility
run: composer require --dev --no-scripts phpunit/phpunit "^7.5" -W

- name: Install dependencies
run: composer install --prefer-dist --no-interaction --no-scripts

Expand Down
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@
"mobiledetect/mobiledetectlib": "^2.8",
"phpcompatibility/phpcompatibility-wp": "^2.0",
"phpstan/phpstan": "^0.12",
"phpunit/php-file-iterator": "2.0.3",
"phpunit/phpunit": "^7.5",
"phpunit/phpunit": "^7.5 || ^8 || ^9",
"psr/container": "1.0.0",
"roave/security-advisories": "dev-master",
"szepeviktor/phpstan-wordpress": "^0.7.0",
Expand All @@ -66,7 +65,7 @@
"wp-media/cloudflare": "^1.0",
"wp-media/module-rocketcdn": "^2.0",
"wp-media/module-varnish": "^2.0",
"wp-media/phpunit": "^2.0",
"wp-media/phpunit": "^3.0",
"wp-media/rocket-lazyload-common": "^3.0",
"wp-media/wp-imagify-partner": "^1.0",
"wpackagist-plugin/amp": "^1.1.4",
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/DIContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class DIContainer implements ArrayAccess {
private $container = [];

public function setUp() : void {
public function setUp() {
add_filter( 'rocket_container', [ $this, 'getContainer' ] );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
'config' => [
'block_external' => true,
'item_url' => 'http://www.example.com/?p=1',
'response_data' => [
'code' => 400,
'body' => '{}',
]
'response' => new WP_Error('code', 'User has blocked requests through HTTP.'),
],
'expected' => [
'code' => 'cpcss_generation_failed',
Expand All @@ -20,10 +17,15 @@
'testShouldBailoutIfResponse400' => [
'config' => [
'item_url' => 'http://www.example.com/?p=1',
'response_data' => [
'code' => 400,
'response' => [
'headers' => [],
'body' => '{}',
]
'response' => [
'code' => 400,
],
'cookies' => [],
'filename' => '',
],
],
'expected' => [
'code' => 'cpcss_generation_failed',
Expand All @@ -34,10 +36,15 @@
'testShouldBailoutIfResponseCodeNotExpected' => [
'config' => [
'item_url' => 'http://www.example.com/?p=2',
'response_data' => [
'code' => 403,
'response' => [
'headers' => [],
'body' => '{}',
]
'response' => [
'code' => 403,
],
'cookies' => [],
'filename' => '',
],
],
'expected' => [
'code' => 'cpcss_generation_failed',
Expand All @@ -48,10 +55,15 @@
'testShouldBailoutIfResponseBodyEmpty' => [
'config' => [
'item_url' => 'http://www.example.com/?p=3',
'response_data' => [
'code' => 200,
'body' => '{}',
]
'response' => [
'headers' => [],
'body' => '',
'response' => [
'code' => 200,
],
'cookies' => [],
'filename' => '',
],
],
'expected' => [
'code' => 'cpcss_generation_failed',
Expand All @@ -62,10 +74,15 @@
'testShouldSucceed' => [
'config' => [
'item_url' => 'http://www.example.com/?p=4',
'response_data' => [
'code' => 200,
'response' => [
'headers' => [],
'body' => '{"success":true,"data":{"id":1}}',
]
'response' => [
'code' => 200,
],
'cookies' => [],
'filename' => '',
],
],
'expected' => [
'success' => true,
Expand All @@ -79,10 +96,15 @@
'config' => [
'item_url' => 'http://www.example.com/?p=1',
'is_mobile' => true,
'response_data' => [
'code' => 400,
'response' => [
'headers' => [],
'body' => '{}',
]
'response' => [
'code' => 400,
],
'cookies' => [],
'filename' => '',
],
],
'expected' => [
'code' => 'cpcss_generation_failed',
Expand All @@ -94,10 +116,15 @@
'config' => [
'item_url' => 'http://www.example.com/?p=2',
'is_mobile' => true,
'response_data' => [
'code' => 403,
'response' => [
'headers' => [],
'body' => '{}',
]
'response' => [
'code' => 403,
],
'cookies' => [],
'filename' => '',
],
],
'expected' => [
'code' => 'cpcss_generation_failed',
Expand All @@ -109,10 +136,15 @@
'config' => [
'item_url' => 'http://www.example.com/?p=3',
'is_mobile' => true,
'response_data' => [
'code' => 200,
'body' => '{}',
]
'response' => [
'headers' => [],
'body' => '',
'response' => [
'code' => 200,
],
'cookies' => [],
'filename' => '',
],
],
'expected' => [
'code' => 'cpcss_generation_failed',
Expand All @@ -124,10 +156,15 @@
'config' => [
'item_url' => 'http://www.example.com/?p=4',
'is_mobile' => true,
'response_data' => [
'code' => 200,
'response' => [
'headers' => [],
'body' => '{"success":true,"data":{"id":1}}',
]
'response' => [
'code' => 200,
],
'cookies' => [],
'filename' => '',
],
],
'expected' => [
'success' => true,
Expand Down
16 changes: 8 additions & 8 deletions tests/Integration/AdminTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace WP_Rocket\Tests\Integration;

use WP_Rocket\Tests\StubTrait;
use WPMedia\PHPUnit\Integration\TestCase as BaseTestCase;
use WP_Rocket\Tests\Integration\TestCase as BaseTestCase;

abstract class AdminTestCase extends BaseTestCase {
use StubTrait;
Expand All @@ -12,16 +12,16 @@ abstract class AdminTestCase extends BaseTestCase {
protected $error_level;
protected $user_id = 0;

public static function setUpBeforeClass() : void {
parent::setUpBeforeClass();
public static function set_up_before_class() {
parent::set_up_before_class();
remove_action( 'admin_init', '_maybe_update_core' );
remove_action( 'admin_init', '_maybe_update_plugins' );
remove_action( 'admin_init', '_maybe_update_themes' );
remove_action( 'admin_init', array( 'WP_Privacy_Policy_Content', 'add_suggested_content' ), 1 );
}

public function setUp() : void {
parent::setUp();
public function set_up() {
parent::set_up();

DBTrait::removeDBHooks();

Expand All @@ -32,20 +32,20 @@ public function setUp() : void {
error_reporting( $this->error_level & ~E_WARNING );
}

public function tearDown() {
public function tear_down() {
$_POST = [];
$_GET = [];
unset( $GLOBALS['post'], $GLOBALS['comment'] );

$this->resetStubProperties();

parent::tearDown();

error_reporting( $this->error_level );
set_current_screen( 'front' );
if ( $this->user_id > 0 ) {
wp_delete_user( $this->user_id );
}

parent::tear_down();
}

protected function setRoleCap( $role_type, $cap ) {
Expand Down
Loading

0 comments on commit 8c603e2

Please sign in to comment.