Skip to content

Commit

Permalink
Add tests and fix existing ones for the latest stripe-mock
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-stripe committed Aug 5, 2020
1 parent b434bcf commit 10fb796
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ matrix:

env:
global:
- STRIPE_MOCK_VERSION=0.90.0
- STRIPE_MOCK_VERSION=0.95.0
cache:
directories:
- $HOME/.composer/cache/files
Expand Down
6 changes: 3 additions & 3 deletions tests/Stripe/AccountLinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public function testIsCreatable()
);
$resource = AccountLink::create([
'account' => 'acct_123',
'failure_url' => 'https://stripe.com/failure',
'success_url' => 'https://stripe.com/success',
'type' => 'custom_account_verification',
'refresh_url' => 'https://stripe.com/refresh_url',
'return_url' => 'https://stripe.com/return_url',
'type' => 'account_onboarding',
]);
static::assertInstanceOf(\Stripe\AccountLink::class, $resource);
}
Expand Down
72 changes: 72 additions & 0 deletions tests/Stripe/PromotionCodeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

namespace Stripe;

/**
* @internal
* @covers \Stripe\PromotionCode
*/
final class PromotionCodeTest extends \PHPUnit\Framework\TestCase
{
use TestHelper;

const TEST_RESOURCE_ID = 'promo_123';

public function testIsListable()
{
$this->expectsRequest(
'get',
'/v1/promotion_codes'
);
$resources = PromotionCode::all();
static::assertInternalType('array', $resources->data);
static::assertInstanceOf(\Stripe\PromotionCode::class, $resources->data[0]);
}

public function testIsRetrievable()
{
$this->expectsRequest(
'get',
'/v1/promotion_codes/' . self::TEST_RESOURCE_ID
);
$resource = PromotionCode::retrieve(self::TEST_RESOURCE_ID);
static::assertInstanceOf(\Stripe\PromotionCode::class, $resource);
}

public function testIsCreatable()
{
$this->expectsRequest(
'post',
'/v1/promotion_codes'
);
$resource = PromotionCode::create([
'coupon' => 'co_123',
'code' => 'MYCODE',
]);
static::assertInstanceOf(\Stripe\PromotionCode::class, $resource);
}

public function testIsSaveable()
{
$resource = PromotionCode::retrieve(self::TEST_RESOURCE_ID);
$resource->metadata['key'] = 'value';
$this->expectsRequest(
'post',
'/v1/promotion_codes/' . self::TEST_RESOURCE_ID
);
$resource->save();
static::assertInstanceOf(\Stripe\PromotionCode::class, $resource);
}

public function testIsUpdatable()
{
$this->expectsRequest(
'post',
'/v1/promotion_codes/' . self::TEST_RESOURCE_ID
);
$resource = PromotionCode::update(self::TEST_RESOURCE_ID, [
'metadata' => ['key' => 'value'],
]);
static::assertInstanceOf(\Stripe\PromotionCode::class, $resource);
}
}
6 changes: 3 additions & 3 deletions tests/Stripe/Service/AccountLinkServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public function testCreate()
);
$resource = $this->service->create([
'account' => 'acct_123',
'failure_url' => 'https://stripe.com/failure',
'success_url' => 'https://stripe.com/success',
'type' => 'custom_account_verification',
'refresh_url' => 'https://stripe.com/refresh_url',
'return_url' => 'https://stripe.com/return_url',
'type' => 'account_onboarding',
]);
static::assertInstanceOf(\Stripe\AccountLink::class, $resource);
}
Expand Down
75 changes: 75 additions & 0 deletions tests/Stripe/Service/PromotionCodeServiceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

namespace Stripe\Service;

/**
* @internal
* @covers \Stripe\Service\PromotionCodeService
*/
final class PromotionCodeServiceTest extends \PHPUnit\Framework\TestCase
{
use \Stripe\TestHelper;

const TEST_RESOURCE_ID = 'promo_123';

/** @var \Stripe\StripeClient */
private $client;

/** @var PromotionCodeService */
private $service;

/**
* @before
*/
protected function setUpService()
{
$this->client = new \Stripe\StripeClient(['api_key' => 'sk_test_123', 'api_base' => MOCK_URL]);
$this->service = new PromotionCodeService($this->client);
}

public function testAll()
{
$this->expectsRequest(
'get',
'/v1/promotion_codes'
);
$resources = $this->service->all();
static::assertInternalType('array', $resources->data);
static::assertInstanceOf(\Stripe\PromotionCode::class, $resources->data[0]);
}

public function testCreate()
{
$this->expectsRequest(
'post',
'/v1/promotion_codes'
);
$resource = $this->service->create([
'coupon' => 'co_123',
'code' => 'MYCODE',
]);
static::assertInstanceOf(\Stripe\PromotionCode::class, $resource);
}

public function testRetrieve()
{
$this->expectsRequest(
'get',
'/v1/promotion_codes/' . self::TEST_RESOURCE_ID
);
$resource = $this->service->retrieve(self::TEST_RESOURCE_ID);
static::assertInstanceOf(\Stripe\PromotionCode::class, $resource);
}

public function testUpdate()
{
$this->expectsRequest(
'post',
'/v1/promotion_codes/' . self::TEST_RESOURCE_ID
);
$resource = $this->service->update(self::TEST_RESOURCE_ID, [
'metadata' => ['key' => 'value'],
]);
static::assertInstanceOf(\Stripe\PromotionCode::class, $resource);
}
}
2 changes: 1 addition & 1 deletion tests/Stripe/Service/SubscriptionItemServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function testCreate()
'/v1/subscription_items'
);
$resource = $this->service->create([
'plan' => 'plan',
'price' => 'price_123',
'subscription' => 'sub_123',
]);
static::assertInstanceOf(\Stripe\SubscriptionItem::class, $resource);
Expand Down
2 changes: 1 addition & 1 deletion tests/Stripe/SubscriptionItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function testIsCreatable()
'/v1/subscription_items'
);
$resource = SubscriptionItem::create([
'plan' => 'plan',
'price' => 'price_123',
'subscription' => 'sub_123',
]);
static::assertInstanceOf(\Stripe\SubscriptionItem::class, $resource);
Expand Down

0 comments on commit 10fb796

Please sign in to comment.