From d6aabc8b2ee56efe332d76adc1e9be12fc7c58fa Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Wed, 16 Oct 2024 22:45:22 +0800 Subject: [PATCH] MDL-83468 phpunit: Add back isInIsolation to testcase This helper has been deprecated in PHPUnit, but we still need it in Moodle. --- lib/phpunit/classes/base_testcase.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/phpunit/classes/base_testcase.php b/lib/phpunit/classes/base_testcase.php index 53b78beea26..b6a2e88655d 100644 --- a/lib/phpunit/classes/base_testcase.php +++ b/lib/phpunit/classes/base_testcase.php @@ -25,6 +25,7 @@ */ use PHPUnit\Framework\MockObject\Rule\InvocationOrder; +use PHPUnit\Framework\TestCase; /** * Base class for PHPUnit test cases customised for Moodle @@ -643,4 +644,18 @@ abstract class base_testcase extends PHPUnit\Framework\TestCase { } }; } + + /** + * Determine whether the test is running in isolation. + * + * Note: This was previously a public method of the TestCase, but as removed in PHPUnit 10. + * There is no direct replacement, but we can use reflection to access the protected property. + * @return bool + */ + public function isInIsolation(): bool { + $rc = new \ReflectionClass(TestCase::class); + $rcp = $rc->getProperty('inIsolation'); + + return $rcp->getValue($this); + } }