Skip to content

Commit

Permalink
Add test (#1243)
Browse files Browse the repository at this point in the history
* Add test
* Fix PHPUnit deprecations
  • Loading branch information
richardm-stripe authored Feb 14, 2022
1 parent 9ed8ab2 commit d4cf933
Show file tree
Hide file tree
Showing 5 changed files with 50 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
26 changes: 26 additions & 0 deletions tests/Stripe/GeneratedExamplesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2696,4 +2696,30 @@ public function testRetrievePaymentLink()
$result = $this->client->paymentLinks->retrieve('pl_xyz', []);
static::assertInstanceOf(\Stripe\PaymentLink::class, $result);
}

public function testVerifyMicrodepositsPaymentIntent()
{
$this->expectsRequest(
'post',
'/v1/payment_intents/pi_xxxxxxxxxxxxx/verify_microdeposits'
);
$result = $this->client->paymentIntents->verifyMicrodeposits(
'pi_xxxxxxxxxxxxx',
[]
);
static::assertInstanceOf(\Stripe\PaymentIntent::class, $result);
}

public function testVerifyMicrodepositsSetupIntent()
{
$this->expectsRequest(
'post',
'/v1/setup_intents/seti_xxxxxxxxxxxxx/verify_microdeposits'
);
$result = $this->client->setupIntents->verifyMicrodeposits(
'seti_xxxxxxxxxxxxx',
[]
);
static::assertInstanceOf(\Stripe\SetupIntent::class, $result);
}
}
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 function compatExpectWarning($warningClass)
{
if (method_exists($this, 'expectWarning')) {
// @phpstan-ignore-next-line
$this->expectWarning($warningClass);
} else {
// @phpstan-ignore-next-line
$this->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 d4cf933

Please sign in to comment.