Created
March 8, 2020 23:03
-
-
Save lukecurtis93/2e113274aa0d7a2f47f4ad235d166cd7 to your computer and use it in GitHub Desktop.
Mock Stripe API with Mockery & Laravel
This file contains hidden or 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
<?php | |
namespace Tests; | |
use Illuminate\Foundation\Testing\TestCase as BaseTestCase; | |
use Stripe\Customer; | |
use Stripe\Stripe; | |
/** | |
* Class TestCase. | |
*/ | |
abstract class TestCase extends BaseTestCase | |
{ | |
use CreatesApplication; | |
// Other methods here for your base test class | |
// In your methods you can call $this->mockStripe() and amend method as expected for additional models if required | |
/** | |
* Mock the stripe models and get some expected results back | |
* | |
* @return null | |
*/ | |
public function mockStripe() | |
{ | |
$this->mock(Stripe::class, function ($mock) { | |
$mock->shouldReceive('setApiKey'); | |
}); | |
$this->mock(Customer::class, function ($mock) { | |
$mock->shouldReceive('create')->andReturn([ | |
'id' => 'test_stripe_customer_id' | |
]); | |
}); | |
} | |
} |
Hey there!
- No it wouldn't the idea is we don't hit the endpoints.
- Yes you're correct, it should actually return a new instance of that (this is an old snippet so may have changed since I last used their SDK)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @lukecurtis93 , a few questions:
Stripe\Customer
, what's the reason behind returning that array?