Skip to content

Commit

Permalink
use HTTP mock
Browse files Browse the repository at this point in the history
  • Loading branch information
jacqueline-stripe committed Sep 10, 2015
1 parent 23f6d70 commit 829c559
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
17 changes: 9 additions & 8 deletions tests/RateLimitErrorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@

class RateLimitErrorTest extends TestCase
{
private function rateLimitErrorResponse()
{
return array(
'error' => array(),
);
}

public function testRateLimit()
{
try {
throw new Error\RateLimit(
"rate limited",
"some_param",
429,
"{'foo':'bar'}",
array('foo' => 'bar')
);
$this->fail("Did not raise error");
$this->mockRequest('GET', '/v1/accounts/acct_DEF', array(), $this->rateLimitErrorResponse(), 429);
Account::retrieve('acct_DEF');
} catch (Error\RateLimit $e) {
$this->assertSame(429, $e->getHttpStatus());
}
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ protected function setUp()
$this->call = 0;
}

protected function mockRequest($method, $path, $params = array(), $return = array('id' => 'myId'))
protected function mockRequest($method, $path, $params = array(), $return = array('id' => 'myId'), $rcode = 200)
{
$mock = $this->setUpMockRequest();
$mock->expects($this->at($this->call++))
->method('request')
->with(strtolower($method), 'https://api.stripe.com' . $path, $this->anything(), $params, false)
->willReturn(array(json_encode($return), 200, array()));
->willReturn(array(json_encode($return), $rcode, array()));
}

private function setUpMockRequest()
Expand Down

0 comments on commit 829c559

Please sign in to comment.