Last active
September 9, 2021 11:18
-
-
Save lukecurtis93/36f0bb8426bc6ba840bad1788cf26d4d to your computer and use it in GitHub Desktop.
Mock Stripe in a Test
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\Unit; | |
use Illuminate\Foundation\Testing\TestCase; | |
use Illuminate\Foundation\Testing\RefreshDatabase; | |
class UserSubscriptionRepositoryTest extends TestCase | |
{ | |
use CreatesApplication, RefreshDatabase; | |
protected $stripeAccountRepository; | |
protected function setUp(): void | |
{ | |
parent::setUp(); | |
$this->mockStripe(); | |
$this->stripeAccountRepository = $this->app->make(StripeAccountRepository::class); | |
} | |
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' | |
]); | |
}); | |
} | |
/** @test */ | |
public function it_correctly_returns_an_new_stripe_account() | |
{ | |
$user = factory(User::class)->create(); | |
$location = factory(Location::class)->create(); | |
$stripe_account = $this->stripeAccountRepository->createCustomer([$user, $location]); | |
$this->assertEquals('test_stripe_customer_id', $stripe_account['id']); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment