Skip to content

Instantly share code, notes, and snippets.

@lukecurtis93
Last active September 9, 2021 11:18
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukecurtis93/36f0bb8426bc6ba840bad1788cf26d4d to your computer and use it in GitHub Desktop.
Save lukecurtis93/36f0bb8426bc6ba840bad1788cf26d4d to your computer and use it in GitHub Desktop.
Mock Stripe in a Test
<?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