Skip to:
Content

bbPress.org

Ticket #3610: wp-env-phpunit-upgrade.patch

File wp-env-phpunit-upgrade.patch, 8.7 KB (added by SirLouen, 3 months ago)

This patch upgrades build tools for WP-ENV and PHPUnit working over it

  • .gitignore

    diff --git .gitignore .gitignore
    index 31e1164a..103b7309 100644
     
    1414/phpcs.xml
    1515/phpunit.xml
    1616/pnpm-lock.yaml
     17.phpunit.result.cache
    1718
    1819# Output directory.
    1920/build/
  • composer.json

    diff --git composer.json composer.json
    index ab12dbcb..7be27081 100644
     
    55        "require-dev": {
    66                "phpcompatibility/phpcompatibility-wp": "^2.1",
    77                "wp-coding-standards/wpcs": "^2.3",
    8                 "dealerdirect/phpcodesniffer-composer-installer": "^0.6.2"
     8                "dealerdirect/phpcodesniffer-composer-installer": "^1.0.0",
     9                "phpunit/phpunit": "^9",
     10                "yoast/phpunit-polyfills": "^3.0"
    911        },
    1012        "minimum-stability": "dev",
    1113        "prefer-stable": true,
     
    1517                ],
    1618                "lint": [
    1719                        "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs"
     20                ],
     21                "test": [
     22                        "@php ./vendor/bin/phpunit -c phpunit.xml.dist"
     23                ],
     24                "phpunit": [
     25                        "@test"
    1826                ]
     27        },
     28        "config": {
     29                "allow-plugins": {
     30                        "composer/installers": true,
     31                        "dealerdirect/phpcodesniffer-composer-installer": true
     32                }
    1933        }
    2034}
  • package.json

    diff --git package.json package.json
    index c73476f5..cbab792e 100644
     
    3030        "devDependencies": {
    3131                "@wordpress/browserslist-config": "~2.1.3",
    3232                "@wordpress/stylelint-config": "~22.4.0",
     33                "@wordpress/env": "^10.8.0",
    3334                "autoprefixer": "~8.2.0",
    3435                "browserslist": "~4.23.2",
    3536                "grunt": "~1.6.1",
     
    4849                "grunt-postcss": "~0.9.0",
    4950                "grunt-rtlcss": "~2.0.2",
    5051                "grunt-sass": "~3.1.0",
    51                 "grunt-stylelint": "~0.8.0",
     52                "grunt-stylelint": "~0.18",
    5253                "grunt-terser": "~2.0.0",
    5354                "grunt-wp-i18n": "~1.0.3",
     55                "grunt-composer": "~0.4.5",
    5456                "matchdep": "~2.0.0",
    5557                "node-sass": "~9.0.0",
    5658                "postcss": "~8.4.40",
    5759                "postcss-markdown": "~1.2.0",
    5860                "postcss-scss": "~1.0.2",
    59                 "stylelint": "~15.11.0",
    60                 "stylelint-scss": "~6.4.1",
     61                "stylelint": "~14",
     62                "stylelint-scss": "~5",
    6163                "terser": "~5.31.3"
     64        },
     65        "scripts": {
     66                "wp-env": "wp-env",
     67                "test-php": "npm run wp-env run cli -- --env-cwd=wp-content/plugins/bbPress composer test"
    6268        }
    6369}
  • phpunit.xml.dist

    diff --git phpunit.xml.dist phpunit.xml.dist
    index dc7a8445..d95eea8c 100644
     
    77        convertWarningsToExceptions="true"
    88        >
    99        <testsuites>
    10                 <testsuite>
     10                <testsuite name="bbPress Test Suite">
    1111                        <directory suffix=".php">tests/phpunit/testcases/</directory>
    1212                </testsuite>
    1313        </testsuites>
     
    2727                        <!-- </arguments>-->
    2828                <!-- </listener>-->
    2929        <!-- </listeners>-->
    30         <filter>
    31                 <whitelist processUncoveredFilesFromWhitelist="true">
    32                         <directory suffix=".php">src</directory>
    33                 </whitelist>
    34         </filter>
     30        <coverage>
     31        <include>
     32            <directory suffix=".php">./src</directory>
     33        </include>
     34        <exclude>
     35            <directory suffix=".php">./tests</directory>
     36            <directory suffix=".php">./vendor</directory>
     37        </exclude>
     38    </coverage>
    3539</phpunit>
  • tests/phpunit/includes/testcase.php

    diff --git tests/phpunit/includes/testcase.php tests/phpunit/includes/testcase.php
    index c5496633..ea773579 100644
    class BBP_UnitTestCase extends WP_UnitTestCase { 
    77        /**
    88         * Fake WP mail globals, to avoid errors
    99         */
    10         public static function setUpBeforeClass() {
     10        public static function setUpBeforeClass(): void {
    1111                add_filter( 'wp_mail',      array( 'BBP_UnitTestCase', 'setUp_wp_mail'    ) );
    1212                add_filter( 'wp_mail_from', array( 'BBP_UnitTestCase', 'tearDown_wp_mail' ) );
    1313        }
    1414
    15         public function setUp() {
     15        public function setUp(): void {
    1616                parent::setUp();
    1717
    1818                $this->factory = new BBP_UnitTest_Factory;
    class BBP_UnitTestCase extends WP_UnitTestCase { 
    3030                }
    3131        }
    3232
    33         public function tearDown() {
     33        public function tearDown(): void {
    3434                global $wpdb;
    3535
    3636                parent::tearDown();
    class BBP_UnitTestCase extends WP_UnitTestCase { 
    5656                parent::clean_up_global_scope();
    5757        }
    5858
    59         function assertPreConditions() {
     59        function assertPreConditions(): void {
    6060                parent::assertPreConditions();
    6161        }
    6262
  • tests/phpunit/testcases/admin/tools.php

    diff --git tests/phpunit/testcases/admin/tools.php tests/phpunit/testcases/admin/tools.php
    index 96914e00..1a54d0cc 100644
     
    77 */
    88class BBP_Tests_Admin_Tools extends BBP_UnitTestCase {
    99        protected $old_current_user = 0;
     10        protected $keymaster_id;
    1011
    11         public function setUp() {
     12        public function setUp(): void {
    1213                parent::setUp();
    1314                $this->old_current_user = get_current_user_id();
    1415                $this->set_current_user( $this->factory->user->create( array( 'role' => 'administrator' ) ) );
    class BBP_Tests_Admin_Tools extends BBP_UnitTestCase { 
    2223                }
    2324        }
    2425
    25         public function tearDown() {
     26        public function tearDown(): void {
    2627                parent::tearDown();
    2728                $this->set_current_user( $this->old_current_user );
    2829        }
  • tests/phpunit/testcases/common/functions.php

    diff --git tests/phpunit/testcases/common/functions.php tests/phpunit/testcases/common/functions.php
    index 0a9740f4..ef20648f 100644
     
    88
    99class BBP_Tests_Common_Functions extends BBP_UnitTestCase {
    1010
     11        protected $old_current_user;
     12        protected $moderator_id;
     13        protected $keymaster_id;
     14
    1115        /**
    1216         * @covers ::bbp_number_format
    1317         * @todo   Implement test_bbp_number_format().
  • tests/phpunit/testcases/common/verify-nonce.php

    diff --git tests/phpunit/testcases/common/verify-nonce.php tests/phpunit/testcases/common/verify-nonce.php
    index 98d621d9..dba7c468 100644
    class BBP_Tests_Common_Functions_BBPVerifyNonceRequest extends BBP_UnitTestCase 
    1010        private $server_port = '';
    1111        private $request_uri = '';
    1212
    13         public function setUp() {
     13        public function setUp(): void {
    1414                parent::setUp();
    1515
    1616                if ( isset( $_SERVER['HTTP_HOST'] ) ) {
    class BBP_Tests_Common_Functions_BBPVerifyNonceRequest extends BBP_UnitTestCase 
    2626                }
    2727        }
    2828
    29         public function tearDown() {
     29        public function tearDown(): void {
    3030                        $_SERVER['HTTP_HOST'] = $this->http_host;
    3131
    3232                        $_SERVER['SERVER_PORT'] = $this->server_port;
  • tests/phpunit/testcases/replies/template/status.php

    diff --git tests/phpunit/testcases/replies/template/status.php tests/phpunit/testcases/replies/template/status.php
    index 588e59d1..30ad0ccc 100644
     
    99 */
    1010class BBP_Tests_Repliess_Template_Status extends BBP_UnitTestCase {
    1111        protected $old_current_user = 0;
     12        protected $keymaster_id;
    1213
    13         public function setUp() {
     14        public function setUp(): void {
    1415                parent::setUp();
    1516                $this->old_current_user = get_current_user_id();
    1617                $this->set_current_user( $this->factory->user->create( array( 'role' => 'administrator' ) ) );
    class BBP_Tests_Repliess_Template_Status extends BBP_UnitTestCase { 
    1819                bbp_set_user_role( $this->keymaster_id, bbp_get_keymaster_role() );
    1920        }
    2021
    21         public function tearDown() {
     22        public function tearDown(): void {
    2223                parent::tearDown();
    2324                $this->set_current_user( $this->old_current_user );
    2425        }
  • tests/phpunit/testcases/topics/functions/topic.php

    diff --git tests/phpunit/testcases/topics/functions/topic.php tests/phpunit/testcases/topics/functions/topic.php
    index ef89acf2..5eec2fdc 100644
     
    99 */
    1010class BBP_Tests_Topics_Functions_Topic extends BBP_UnitTestCase {
    1111
     12        protected $old_current_user;
     13    protected $keymaster_id;
     14
    1215        /**
    1316         * @group canonical
    1417         * @covers ::bbp_insert_topic
  • tests/phpunit/testcases/users/template/user.php

    diff --git tests/phpunit/testcases/users/template/user.php tests/phpunit/testcases/users/template/user.php
    index 60ef23c0..91579633 100644
     
    88 */
    99class BBP_Tests_Users_Template_User extends BBP_UnitTestCase {
    1010
     11    protected $keymaster_userdata;
     12        protected $keymaster_id;
    1113        protected $old_current_user = 0;
    1214
    13         public function setUp() {
     15        public function setUp(): void {
    1416                parent::setUp();
    1517                $this->old_current_user = get_current_user_id();
    1618                $this->set_current_user( $this->factory->user->create( array( 'role' => 'administrator' ) ) );
    class BBP_Tests_Users_Template_User extends BBP_UnitTestCase { 
    1921                bbp_set_user_role( $this->keymaster_id, bbp_get_keymaster_role() );
    2022        }
    2123
    22         public function tearDown() {
     24        public function tearDown(): void {
    2325                parent::tearDown();
    2426                $this->set_current_user( $this->old_current_user );
    2527        }
    class BBP_Tests_Users_Template_User extends BBP_UnitTestCase { 
    3739                $this->assertSame( $this->keymaster_id, $user_id );
    3840
    3941                // Output.
    40                 $this->expectOutputString( $formatted_value );
    41                 bbp_user_id( $this->keymaster_id );
     42                $this->expectOutputRegex( '/' . preg_quote($formatted_value, '/') . '/' );
     43        bbp_user_id( $this->keymaster_id );
    4244        }
    4345
    4446        /**