Quantcast
Channel: Laravel News
Viewing all articles
Browse latest Browse all 1795

Laravel Spark Open Sources its Integration Tests

$
0
0

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.


Viewing all articles
Browse latest Browse all 1795

Trending Articles