Join 6,000+ Laravel Developers on March 6, 2019 for Laracon Online. Get your tickets today!
Laravel Spark Open Sources its Integration Tests
Laravel Tutorials / November 17, 2016

Laravel Spark Open Sources its Integration Tests

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:

public function test_events_are_fired_when_subscriptions_are_deleted()
    $user = $this->createSubscribedUser('spark-test-1');
    $this->json('POST', '/webhook/stripe', [
        'type' => 'customer.subscription_deleted',
        'id' => 'event-id',
        'data' => [
            'object' => [
                'id' => $user->subscriptions->first()->stripe_id,
                'customer' => $user->stripe_id,

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

$user = $this->createSubscribedUser('spark-test-1');
    '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.

Laravel News Partners


Join the weekly newsletter and never miss out on new tips, tutorials, and more.