Skip to content

Commit

Permalink
Merge pull request #519 from stripe/ob-file-upload-stripe-mock
Browse files Browse the repository at this point in the history
Use stripe-mock for FileUpload tests
  • Loading branch information
ob-stripe authored Sep 17, 2018
2 parents eb117cf + e927ca9 commit b078870
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 44 deletions.
52 changes: 8 additions & 44 deletions tests/Stripe/FileUploadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,68 +6,35 @@ class FileUploadTest extends TestCase
{
const TEST_RESOURCE_ID = 'file_123';

/**
* @before
*/
public function setUpFixture()
{
// PHP <= 5.5 does not support arrays as class constants, so we set up
// the fixture as an instance variable.
$this->fixture = [
'id' => self::TEST_RESOURCE_ID,
'object' => 'file_upload',
];
}

public function testIsListable()
{
$this->stubRequest(
$this->expectsRequest(
'get',
'/v1/files',
[],
null,
false,
[
'object' => 'list',
'data' => [$this->fixture],
'resource_url' => '/v1/files',
],
200,
Stripe::$apiUploadBase
'/v1/files'
);

$resources = FileUpload::all();
$this->assertTrue(is_array($resources->data));
$this->assertInstanceOf("Stripe\\FileUpload", $resources->data[0]);
}

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

public function testIsCreatableWithFileHandle()
{
$this->stubRequest(
$this->expectsRequest(
'post',
'/v1/files',
null,
['Content-Type: multipart/form-data'],
true,
$this->fixture,
200,
Stripe::$apiUploadBase
true
);
$fp = fopen(dirname(__FILE__) . '/../data/test.png', 'r');
$resource = FileUpload::create([
Expand All @@ -84,15 +51,12 @@ public function testIsCreatableWithCurlFile()
return;
}

$this->stubRequest(
$this->expectsRequest(
'post',
'/v1/files',
null,
['Content-Type: multipart/form-data'],
true,
$this->fixture,
200,
Stripe::$apiUploadBase
true
);
$curlFile = new \CurlFile(dirname(__FILE__) . '/../data/test.png');
$resource = FileUpload::create([
Expand Down
6 changes: 6 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ class TestCase extends \PHPUnit_Framework_TestCase
/** @var string original API key */
protected $origApiKey;

/** @var string original upload base URL */
protected $origApiUploadBase;

/** @var string original client ID */
protected $origClientId;

Expand All @@ -30,13 +33,15 @@ protected function setUp()
// Save original values so that we can restore them after running tests
$this->origApiBase = Stripe::$apiBase;
$this->origApiKey = Stripe::getApiKey();
$this->origApiUploadBase = Stripe::$apiUploadBase;
$this->origClientId = Stripe::getClientId();
$this->origApiVersion = Stripe::getApiVersion();
$this->origAccountId = Stripe::getAccountId();

// Set up host and credentials for stripe-mock
Stripe::$apiBase = "http://localhost:" . MOCK_PORT;
Stripe::setApiKey("sk_test_123");
Stripe::$apiUploadBase = "http://localhost:" . MOCK_PORT;
Stripe::setClientId("ca_123");
Stripe::setApiVersion(null);
Stripe::setAccountId(null);
Expand All @@ -53,6 +58,7 @@ protected function tearDown()
// Restore original values
Stripe::$apiBase = $this->origApiBase;
Stripe::setApiKey($this->origApiKey);
Stripe::$apiUploadBase = $this->origApiUploadBase;
Stripe::setClientId($this->origClientId);
Stripe::setApiVersion($this->origApiVersion);
Stripe::setAccountId($this->origAccountId);
Expand Down

0 comments on commit b078870

Please sign in to comment.