Skip to content

Commit

Permalink
Move Payment Intent to stripe-mock
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-stripe committed Jul 9, 2018
1 parent be46d55 commit 0f09abb
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 89 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ php:

env:
global:
- STRIPE_MOCK_VERSION=0.16.0
- STRIPE_MOCK_VERSION=0.19.0
matrix:
- AUTOLOAD=1
- AUTOLOAD=0
Expand Down
117 changes: 30 additions & 87 deletions tests/Stripe/PaymentIntentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,11 @@ class PaymentIntentTest extends TestCase
{
const TEST_RESOURCE_ID = 'pi_123';

// stripe-mock does not support /v1/payment_intents yet so we stub it
// and create a fixture for it
public function createFixture()
{
$base = [
'id' => self::TEST_RESOURCE_ID,
'object' => 'payment_intent',
'metadata' => [],
];
return PaymentIntent::constructFrom(
$base,
new Util\RequestOptions()
);
}

public function testIsListable()
{
$this->stubRequest(
$this->expectsRequest(
'get',
'/v1/payment_intents',
[],
null,
false,
[
"object" => "list",
"data" => [
$this->createFixture()
]
]
'/v1/payment_intents'
);
$resources = PaymentIntent::all();
$this->assertTrue(is_array($resources->data));
Expand All @@ -43,116 +19,83 @@ public function testIsListable()

public function testIsRetrievable()
{
$this->stubRequest(
$this->expectsRequest(
'get',
'/v1/payment_intents/' . self::TEST_RESOURCE_ID,
[],
null,
false,
$this->createFixture()
'/v1/payment_intents/' . self::TEST_RESOURCE_ID
);
$resource = PaymentIntent::retrieve(self::TEST_RESOURCE_ID);
$this->assertInstanceOf("Stripe\\PaymentIntent", $resource);
}

public function testIsCreatable()
{
$params = [
$this->expectsRequest(
'post',
'/v1/payment_intents'
);
$resource = PaymentIntent::create([
"allowed_source_types" => ["card"],
"amount" => 100,
"currency" => "usd",
];

$this->stubRequest(
'post',
'/v1/payment_intents',
$params,
null,
false,
$this->createFixture()
);
$resource = PaymentIntent::create($params);
]);
$this->assertInstanceOf("Stripe\\PaymentIntent", $resource);
}

public function testIsSaveable()
{
$params = [
"metadata" => ["key" => "value"],
];

$resource = $this->createFixture();
$resource = PaymentIntent::retrieve(self::TEST_RESOURCE_ID);
$resource->metadata["key"] = "value";
$this->stubRequest(
$this->expectsRequest(
'post',
'/v1/payment_intents/' . $resource->id,
$params,
null,
false,
$this->createFixture()
'/v1/payment_intents/' . self::TEST_RESOURCE_ID
);
$resource->save();
$this->assertInstanceOf("Stripe\\PaymentIntent", $resource);
}

public function testIsUpdatable()
{
$params = [
"metadata" => ["key" => "value"],
];

$this->stubRequest(
$this->expectsRequest(
'post',
'/v1/payment_intents/' . self::TEST_RESOURCE_ID,
$params,
null,
false,
$this->createFixture()
'/v1/payment_intents/' . self::TEST_RESOURCE_ID
);
$resource = PaymentIntent::update(
self::TEST_RESOURCE_ID,
[
"metadata" => ["key" => "value"],
]
);
$resource = PaymentIntent::update(self::TEST_RESOURCE_ID, $params);
$this->assertInstanceOf("Stripe\\PaymentIntent", $resource);
}

public function testIsCancelable()
{
$resource = $this->createFixture();
$this->stubRequest(
$resource = PaymentIntent::retrieve(self::TEST_RESOURCE_ID);
$this->expectsRequest(
'post',
'/v1/payment_intents/' . $resource->id . '/cancel',
[],
null,
false,
$this->createFixture()
'/v1/payment_intents/' . self::TEST_RESOURCE_ID . '/cancel'
);
$resource->cancel();
$this->assertInstanceOf("Stripe\\PaymentIntent", $resource);
}

public function testIsCapturable()
{
$resource = $this->createFixture();
$this->stubRequest(
$resource = PaymentIntent::retrieve(self::TEST_RESOURCE_ID);
$this->expectsRequest(
'post',
'/v1/payment_intents/' . $resource->id . '/capture',
[],
null,
false,
$this->createFixture()
'/v1/payment_intents/' . self::TEST_RESOURCE_ID . '/capture'
);
$resource->capture();
$this->assertInstanceOf("Stripe\\PaymentIntent", $resource);
}

public function testIsConfirmable()
{
$resource = $this->createFixture();
$this->stubRequest(
$resource = PaymentIntent::retrieve(self::TEST_RESOURCE_ID);
$this->expectsRequest(
'post',
'/v1/payment_intents/' . $resource->id . '/confirm',
[],
null,
false,
$this->createFixture()
'/v1/payment_intents/' . self::TEST_RESOURCE_ID . '/confirm'
);
$resource->confirm();
$this->assertInstanceOf("Stripe\\PaymentIntent", $resource);
Expand Down
2 changes: 1 addition & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

define("MOCK_MINIMUM_VERSION", "0.16.0");
define("MOCK_MINIMUM_VERSION", "0.19.0");
define("MOCK_PORT", getenv("STRIPE_MOCK_PORT") ?: 12111);

// Send a request to stripe-mock
Expand Down

0 comments on commit 0f09abb

Please sign in to comment.