summaryrefslogtreecommitdiffstatshomepage
path: root/tests/phpunit/includes/phpunit7
diff options
context:
space:
mode:
authorSergey Biryukov <sergeybiryukov@git.wordpress.org>2020-09-13 02:36:48 +0000
committerSergey Biryukov <sergeybiryukov@git.wordpress.org>2020-09-13 02:36:48 +0000
commit1a89e6383888223e2883d96b31941c65c00c4616 (patch)
treed995ba0bc745cfefc0803fb44be719191ef2d513 /tests/phpunit/includes/phpunit7
parent9066eb15a2f6ded6e52b93d01544c56260fcb589 (diff)
downloadwordpress-1a89e6383888223e2883d96b31941c65c00c4616.tar.gz
wordpress-1a89e6383888223e2883d96b31941c65c00c4616.zip
Tests: Replace the native PHPUnit `getMockForAbstractClass()` and `getMockBuilder()` methods.
This avoids parse errors in PHPUnit internals due to `match` being a reserved keyword in PHP 8. To run on PHP 8, the tests relying on these methods require PHPUnit 9.3 or later. When the test suite is updated for compatibility with PHPUnit 9.x, these overrides can be removed. See #50913, #50902. git-svn-id: https://develop.svn.wordpress.org/trunk@48972 602fd350-edb4-49c9-b593-d223f7449a82
Diffstat (limited to 'tests/phpunit/includes/phpunit7')
-rw-r--r--tests/phpunit/includes/phpunit7/testcase.php60
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/phpunit/includes/phpunit7/testcase.php b/tests/phpunit/includes/phpunit7/testcase.php
index 9a8ddc12de..948f5799de 100644
--- a/tests/phpunit/includes/phpunit7/testcase.php
+++ b/tests/phpunit/includes/phpunit7/testcase.php
@@ -37,4 +37,64 @@ class WP_UnitTestCase extends WP_UnitTestCase_Base {
static::assertThat( $actual, $constraint, $message );
}
+
+ /**
+ * Returns a mock object for the specified abstract class with all abstract
+ * methods of the class mocked. Concrete methods to mock can be specified with
+ * the last parameter.
+ *
+ * This method replaces the native PHPUnit method to avoid parse errors
+ * due to `match` being a reserved keyword in PHP 8.
+ *
+ * To run on PHP 8, the tests using this method require PHPUnit 9.3 or later.
+ *
+ * When the test suite is updated for compatibility with PHPUnit 9.x,
+ * this override can be removed.
+ *
+ * @since 5.6.0
+ *
+ * @param string $original_class_name
+ * @param string $mock_class_name
+ * @param bool $call_original_constructor
+ * @param bool $call_original_clone
+ * @param bool $call_autoload
+ * @param array $mocked_methods
+ * @param bool $clone_arguments
+ *
+ * @throws \ReflectionException
+ * @throws RuntimeException
+ * @throws Exception
+ *
+ * @return MockObject
+ */
+ public function getMockForAbstractClass( $original_class_name, array $arguments = array(), $mock_class_name = '', $call_original_constructor = true, $call_original_clone = true, $call_autoload = true, $mocked_methods = array(), $clone_arguments = false ): PHPUnit\Framework\MockObject\MockObject {
+ if ( PHP_VERSION_ID >= 80000 && version_compare( tests_get_phpunit_version(), '9.3', '<' ) ) {
+ $this->markTestSkipped( 'To run on PHP 8, this test requires PHPUnit 9.3 or later.' );
+ }
+
+ return parent::getMockForAbstractClass( $original_class_name, $arguments, $mock_class_name, $call_original_constructor, $call_original_clone, $call_autoload, $mocked_methods, $clone_arguments );
+ }
+
+ /**
+ * Returns a builder object to create mock objects using a fluent interface.
+ *
+ * This method replaces the native PHPUnit method to avoid parse errors
+ * due to `match` being a reserved keyword in PHP 8.
+ *
+ * To run on PHP 8, the tests using this method require PHPUnit 9.3 or later.
+ *
+ * When the test suite is updated for compatibility with PHPUnit 9.x,
+ * this override can be removed.
+ *
+ * @since 5.6.0
+ *
+ * @param string|string[] $class_name
+ */
+ public function getMockBuilder( $class_name ): PHPUnit\Framework\MockObject\MockBuilder {
+ if ( PHP_VERSION_ID >= 80000 && version_compare( tests_get_phpunit_version(), '9.3', '<' ) ) {
+ $this->markTestSkipped( 'To run on PHP 8, this test requires PHPUnit 9.3 or later.' );
+ }
+
+ return parent::getMockBuilder( $class_name );
+ }
}