Laravel Spark Open Sources its Integration Tests

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()
{
    $this->expectsEvents(SubscriptionCancelled::class);
    $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,
            ],
        ],
    ]);
    $this->seeStatusCode(200);
}

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

$user = $this->createSubscribedUser('spark-test-1');
$user->forceFill([
    'card_country' => 'US',
])->save();

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: Laravel Tutorials / Spark / Testing


Newsletter

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

Laravel News Partners

Laravel Jobs

Lead Front End Developer
Remote
continued
Full-Stack Laravel Developer
Cologne
Revive Interior
Intermediate PHP Developer (Full Stack | CakePHP | Laravel | Vue | jQuery)
Remote
continued
Senior PHP Developer (Full Stack | CakePHP | Laravel | Vue | jQuery)
Remote
continued
Laravel Developer
Amsterdam (partially remote possible)
Let's Book
Web Developer (Laravel)
Tweed Heads, New South Wales, AUSTRALIA
Tursa Employment & Training
Laravel Experts needed-Remote position
Remote
Golden Sky ROI