|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Omnipay\Stripe\Message; |
| 4 | + |
| 5 | +use Omnipay\Tests\TestCase; |
| 6 | + |
| 7 | +class FetchTokenRequestTest extends TestCase |
| 8 | +{ |
| 9 | + /** |
| 10 | + * @var FetchTokenRequest |
| 11 | + */ |
| 12 | + private $request; |
| 13 | + |
| 14 | + public function setUp() |
| 15 | + { |
| 16 | + $this->request = new FetchTokenRequest($this->getHttpClient(), $this->getHttpRequest()); |
| 17 | + $this->request->setToken('tok_15Kuns2eZvKYlo2CDt9wRdzS'); |
| 18 | + } |
| 19 | + |
| 20 | + public function testEndpoint() |
| 21 | + { |
| 22 | + $this->assertSame('https://api.stripe.com/v1/tokens/tok_15Kuns2eZvKYlo2CDt9wRdzS', $this->request->getEndpoint()); |
| 23 | + } |
| 24 | + |
| 25 | + public function testSendSuccess() |
| 26 | + { |
| 27 | + $this->setMockHttpResponse('FetchTokenSuccess.txt'); |
| 28 | + $response = $this->request->send(); |
| 29 | + |
| 30 | + $this->assertTrue($response->isSuccessful()); |
| 31 | + $this->assertFalse($response->isRedirect()); |
| 32 | + $this->assertSame('tok_15Kuns2eZvKYlo2CDt9wRdzS', $response->getToken()); |
| 33 | + $this->assertInternalType('array', $response->getCard()); |
| 34 | + $this->assertNull($response->getMessage()); |
| 35 | + } |
| 36 | + |
| 37 | + public function testSendError() |
| 38 | + { |
| 39 | + $this->setMockHttpResponse('FetchTokenFailure.txt'); |
| 40 | + $response = $this->request->send(); |
| 41 | + |
| 42 | + $this->assertFalse($response->isSuccessful()); |
| 43 | + $this->assertFalse($response->isRedirect()); |
| 44 | + $this->assertNull($response->getToken()); |
| 45 | + $this->assertNull($response->getCard()); |
| 46 | + $this->assertSame('No such token: tok_15Kuns2eZvKYlo2CDt9wRdzS', $response->getMessage()); |
| 47 | + } |
| 48 | +} |
0 commit comments