Skip to content

Commit

Permalink
Fix PHPUnit deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
richardm-stripe committed Feb 12, 2022
1 parent 59e0a67 commit 82ed009
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion tests/Stripe/BaseStripeClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
2 changes: 1 addition & 1 deletion tests/Stripe/StripeObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
Expand Down
2 changes: 1 addition & 1 deletion tests/Stripe/Util/DefaultLoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
21 changes: 21 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

0 comments on commit 82ed009

Please sign in to comment.