From 82ed0092736480d9652d2880de09a1cdd909cf6b Mon Sep 17 00:00:00 2001 From: Richard Marmorstein Date: Fri, 11 Feb 2022 16:50:38 -0800 Subject: [PATCH] Fix PHPUnit deprecations --- tests/Stripe/BaseStripeClientTest.php | 2 +- tests/Stripe/StripeObjectTest.php | 2 +- tests/Stripe/Util/DefaultLoggerTest.php | 2 +- tests/TestCase.php | 21 +++++++++++++++++++++ 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/tests/Stripe/BaseStripeClientTest.php b/tests/Stripe/BaseStripeClientTest.php index 442e660a2f..561af37d0f 100644 --- a/tests/Stripe/BaseStripeClientTest.php +++ b/tests/Stripe/BaseStripeClientTest.php @@ -181,7 +181,7 @@ public function testRequestCollectionThrowsForNonList() public function testRequestWithOptsInParamsWarns() { - $this->expectException(static::compatWarningClass()); + $this->compatExpectWarning(static::compatWarningClass()); $this->expectExceptionMessage('Options found in $params: api_key, stripe_account, api_base. Options should be ' . 'passed in their own array after $params. (HINT: pass an empty array to $params if you do not have any.)'); $client = new BaseStripeClient([ diff --git a/tests/Stripe/StripeObjectTest.php b/tests/Stripe/StripeObjectTest.php index 16099122de..94e0538b4f 100644 --- a/tests/Stripe/StripeObjectTest.php +++ b/tests/Stripe/StripeObjectTest.php @@ -144,7 +144,7 @@ public function testNonexistentProperty() $s = new StripeObject(); static::assertNull($s->nonexistent); - static::assertRegExp( + static::compatAssertMatchesRegularExpression( '/Stripe Notice: Undefined property of Stripe\\\\StripeObject instance: nonexistent/', \stream_get_contents($capture) ); diff --git a/tests/Stripe/Util/DefaultLoggerTest.php b/tests/Stripe/Util/DefaultLoggerTest.php index 770a26b80a..5d607fc9bf 100644 --- a/tests/Stripe/Util/DefaultLoggerTest.php +++ b/tests/Stripe/Util/DefaultLoggerTest.php @@ -22,7 +22,7 @@ public function testDefaultLogger() $logger = new DefaultLogger(); $logger->error('This is a test message'); - static::assertRegExp('/This is a test message/', \stream_get_contents($capture)); + static::compatAssertMatchesRegularExpression('/This is a test message/', \stream_get_contents($capture)); } finally { \ini_set('error_log', $origErrorLog); \fclose($capture); diff --git a/tests/TestCase.php b/tests/TestCase.php index e5291140b3..1d13d91d60 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -67,4 +67,25 @@ public static function compatWarningClass() // @phpstan-ignore-next-line return \PHPUnit_Framework_Error_Warning::class; } + + public static function compatExpectWarning($warningClass) + { + if (method_exists(static::class, 'expectWarning')) { + // @phpstan-ignore-next-line + static::expectWarning($warningClass); + } else { + // @phpstan-ignore-next-line + static::expectException($warningClass); + } + } + + public static function compatAssertMatchesRegularExpression($text, $regex) { + if (method_exists(static::class, 'assertMatchesRegularExpression')) { + // @phpstan-ignore-next-line + static::assertMatchesRegularExpression($text, $regex); + } else { + // @phpstan-ignore-next-line + static::assertRegExp($text, $regex); + } + } }