From 0f09abbc01b4c85eadeb073848ed640945eb4a80 Mon Sep 17 00:00:00 2001 From: Remi Jannel Date: Sat, 7 Jul 2018 16:18:52 -0400 Subject: [PATCH] Move Payment Intent to stripe-mock --- .travis.yml | 2 +- tests/Stripe/PaymentIntentTest.php | 117 ++++++++--------------------- tests/bootstrap.php | 2 +- 3 files changed, 32 insertions(+), 89 deletions(-) diff --git a/.travis.yml b/.travis.yml index fb7b41f86..71fc17f0d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ php: env: global: - - STRIPE_MOCK_VERSION=0.16.0 + - STRIPE_MOCK_VERSION=0.19.0 matrix: - AUTOLOAD=1 - AUTOLOAD=0 diff --git a/tests/Stripe/PaymentIntentTest.php b/tests/Stripe/PaymentIntentTest.php index ad8ec08da..acae9bc8f 100644 --- a/tests/Stripe/PaymentIntentTest.php +++ b/tests/Stripe/PaymentIntentTest.php @@ -6,35 +6,11 @@ class PaymentIntentTest extends TestCase { const TEST_RESOURCE_ID = 'pi_123'; - // stripe-mock does not support /v1/payment_intents yet so we stub it - // and create a fixture for it - public function createFixture() - { - $base = [ - 'id' => self::TEST_RESOURCE_ID, - 'object' => 'payment_intent', - 'metadata' => [], - ]; - return PaymentIntent::constructFrom( - $base, - new Util\RequestOptions() - ); - } - public function testIsListable() { - $this->stubRequest( + $this->expectsRequest( 'get', - '/v1/payment_intents', - [], - null, - false, - [ - "object" => "list", - "data" => [ - $this->createFixture() - ] - ] + '/v1/payment_intents' ); $resources = PaymentIntent::all(); $this->assertTrue(is_array($resources->data)); @@ -43,13 +19,9 @@ public function testIsListable() public function testIsRetrievable() { - $this->stubRequest( + $this->expectsRequest( 'get', - '/v1/payment_intents/' . self::TEST_RESOURCE_ID, - [], - null, - false, - $this->createFixture() + '/v1/payment_intents/' . self::TEST_RESOURCE_ID ); $resource = PaymentIntent::retrieve(self::TEST_RESOURCE_ID); $this->assertInstanceOf("Stripe\\PaymentIntent", $resource); @@ -57,39 +29,25 @@ public function testIsRetrievable() public function testIsCreatable() { - $params = [ + $this->expectsRequest( + 'post', + '/v1/payment_intents' + ); + $resource = PaymentIntent::create([ "allowed_source_types" => ["card"], "amount" => 100, "currency" => "usd", - ]; - - $this->stubRequest( - 'post', - '/v1/payment_intents', - $params, - null, - false, - $this->createFixture() - ); - $resource = PaymentIntent::create($params); + ]); $this->assertInstanceOf("Stripe\\PaymentIntent", $resource); } public function testIsSaveable() { - $params = [ - "metadata" => ["key" => "value"], - ]; - - $resource = $this->createFixture(); + $resource = PaymentIntent::retrieve(self::TEST_RESOURCE_ID); $resource->metadata["key"] = "value"; - $this->stubRequest( + $this->expectsRequest( 'post', - '/v1/payment_intents/' . $resource->id, - $params, - null, - false, - $this->createFixture() + '/v1/payment_intents/' . self::TEST_RESOURCE_ID ); $resource->save(); $this->assertInstanceOf("Stripe\\PaymentIntent", $resource); @@ -97,32 +55,25 @@ public function testIsSaveable() public function testIsUpdatable() { - $params = [ - "metadata" => ["key" => "value"], - ]; - - $this->stubRequest( + $this->expectsRequest( 'post', - '/v1/payment_intents/' . self::TEST_RESOURCE_ID, - $params, - null, - false, - $this->createFixture() + '/v1/payment_intents/' . self::TEST_RESOURCE_ID + ); + $resource = PaymentIntent::update( + self::TEST_RESOURCE_ID, + [ + "metadata" => ["key" => "value"], + ] ); - $resource = PaymentIntent::update(self::TEST_RESOURCE_ID, $params); $this->assertInstanceOf("Stripe\\PaymentIntent", $resource); } public function testIsCancelable() { - $resource = $this->createFixture(); - $this->stubRequest( + $resource = PaymentIntent::retrieve(self::TEST_RESOURCE_ID); + $this->expectsRequest( 'post', - '/v1/payment_intents/' . $resource->id . '/cancel', - [], - null, - false, - $this->createFixture() + '/v1/payment_intents/' . self::TEST_RESOURCE_ID . '/cancel' ); $resource->cancel(); $this->assertInstanceOf("Stripe\\PaymentIntent", $resource); @@ -130,14 +81,10 @@ public function testIsCancelable() public function testIsCapturable() { - $resource = $this->createFixture(); - $this->stubRequest( + $resource = PaymentIntent::retrieve(self::TEST_RESOURCE_ID); + $this->expectsRequest( 'post', - '/v1/payment_intents/' . $resource->id . '/capture', - [], - null, - false, - $this->createFixture() + '/v1/payment_intents/' . self::TEST_RESOURCE_ID . '/capture' ); $resource->capture(); $this->assertInstanceOf("Stripe\\PaymentIntent", $resource); @@ -145,14 +92,10 @@ public function testIsCapturable() public function testIsConfirmable() { - $resource = $this->createFixture(); - $this->stubRequest( + $resource = PaymentIntent::retrieve(self::TEST_RESOURCE_ID); + $this->expectsRequest( 'post', - '/v1/payment_intents/' . $resource->id . '/confirm', - [], - null, - false, - $this->createFixture() + '/v1/payment_intents/' . self::TEST_RESOURCE_ID . '/confirm' ); $resource->confirm(); $this->assertInstanceOf("Stripe\\PaymentIntent", $resource); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 6ee856c0d..321eaaec0 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,6 +1,6 @@