Laravel Spark Open Sources its Integration Tests


November 17th, 2016


Spark is a commercial Laravel package that provides scaffolding for quickly setting up a SaaS app and more. Spark was officially released back in April, and they have just made available a repository holding all the integration tests.

Even if you are not a Spark customer, this can be useful as a learning resource to see how they structured and utilized integration testing within the project.

One example of this is within the StripeWebhookControllerTest. It includes examples of testing with web hooks:

1public function test_events_are_fired_when_subscriptions_are_deleted()
3 $this->expectsEvents(SubscriptionCancelled::class);
4 $user = $this->createSubscribedUser('spark-test-1');
5 $this->json('POST', '/webhook/stripe', [
6 'type' => 'customer.subscription_deleted',
7 'id' => 'event-id',
8 'data' => [
9 'object' => [
10 'id' => $user->subscriptions->first()->stripe_id,
11 'customer' => $user->stripe_id,
12 ],
13 ],
14 ]);
15 $this->seeStatusCode(200);

Then in that same file I came across a forceFill method on an Eloquent model:

1$user = $this->createSubscribedUser('spark-test-1');
3 'card_country' => 'US',

This allows you to fill the model with an array of attributes and bypass the mass assignment. Which is handy when writing your tests.

If you are looking for examples of tests from a real world app, give it a look, and you might just pick up on some new framework features in the process.

Filed in:

Eric L. Barnes

Eric is the creator of Laravel News and has been covering Laravel since 2012.

Laravel News Partners