-
Notifications
You must be signed in to change notification settings - Fork 858
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests and fix existing ones for the latest stripe-mock
- Loading branch information
1 parent
b434bcf
commit 10fb796
Showing
7 changed files
with
156 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters