PHPackages                             savvywombat/laravel-test-utils - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. savvywombat/laravel-test-utils

ActiveLibrary[Testing &amp; Quality](/categories/testing)

savvywombat/laravel-test-utils
==============================

Utilities and helpers for testing Laravel based applications

0.6(5y ago)024MITPHPPHP ^7.2

Since Nov 13Pushed 5y ago1 watchersCompare

[ Source](https://github.com/SavvyWombat/laravel-test-utils)[ Packagist](https://packagist.org/packages/savvywombat/laravel-test-utils)[ Docs](https://github.com/SavvyWombat/laravel-test-utils)[ RSS](/packages/savvywombat-laravel-test-utils/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (2)Versions (6)Used By (0)

Laravel test utilities
======================

[](#laravel-test-utilities)

Utilities and helpers for testing Laravel based applications

`composer require --dev savvywombat/laravel-test-utils`

Database casting helpers
------------------------

[](#database-casting-helpers)

```
use SavvyWombat\LaravelTestUtils\DBCast
```

### DBCast::toJson

[](#dbcasttojson)

Use this helper when asserting against the database (such as with assertDatabaseHas or assertDatabaseMissing) to cast an array or json string to a JSON datatype.

```
$this->assertDatabaseHas('vehicles', [
    'id' => 1,
    'manufacturer' => 'Toyford',
    'model' => 'Llama',
    'attributes' => DBCast::toJson([
        'color' => 'indigo green',
        'engine' => '2 litres 4-cylinder',
        'gearbox' => '6-speed manual',
        'doors' => '5',
    ]),
]);
```

### DBCast::toTimestamp

[](#dbcasttotimestamp)

User this helper to assert Datetime or Carbon instances against timestamps in the database.

```
$trip = Trip::factory()->create();

Carbon::setTestNow("2020-10-20 10:15:43");

$response = $this->get('/start-trip');

$response->assertStatus(200)
    ->assertSee('Trip started');

$this->assertDatabaseHas('trips', [
    'id' => $trip->id,
    'trip_started_at' => DBCast::toTimestamp(Carbon::now()),
]);

Carbon::setTestNow();
```

Mock guzzle
-----------

[](#mock-guzzle)

This trait assumes that you are using Laravel's IoC to inject the Guzzle client into your code.

Say we're testing a contact form with a Google Recaptcha:

```
namespace App\Http\Controllers;

use GuzzleHttp\Client;
use Illuminate\Http\Request;

class ContactController extends Controller
{
    public function send(Request $request, Client $client)
    {
        // Validate ReCaptcha
        $response = $this->client->post(config('recaptcha.url'), [
            'query' => [
                'secret' => config('recaptcha.secret'),
                'response' => $request->input(['g-recaptcha-token'], ''),
            ]
        ]);

        if (json_decode($response->getBody())->success) {
            redirect()->route('contact::success');
        } else {
            redirect()->route('contact::form')->withErrors(['g-recaptcha-token' => 'Please confirm you are a human!']);
    }
}
```

```
namespace Tests\Feature;

use GuzzleHttp\Psr7\Response;
use SavvyWombat\LaravelTestUtils\MocksGuzzle;
use Tests\TestCase;

class MyTest extends TestCase
{
    use MocksGuzzle;

    /** @test */
    public function it_reacts_appropriately_to_recaptcha_success()
    {
        $this->guzzle() // this is guzzle's MockHandler class
            ->append(new Response(200, [], json_encode(['success' => 'true'])));

        $this->post('/some-url', ['message' => 'some message', 'g-recaptcha-token' => 'blah'])
            ->assertStatus(302)
            ->assertSessionHasNoErrors()
            ->assertRedirect('/success');
    }

    /** @test */
    public function it_errors_on_recaptcha_failure()
    {
        $this->guzzle() // this is guzzle's MockHandler class
            ->append(new Response(200, [], json_encode(['success' => 'false'])));

        $this->post('/some-url', ['message' => 'some message', 'g-recaptcha-token' => 'blah'])
            ->assertStatus(302)
            ->assertSessionHasErrors('g-recaptcha-token')
            ->assertRedirect('/some-url');
    }
}
```

If your controller or other code needs to make more than one request to an API, you can chain responses to the guzzle handler:

```
$this->guzzle()
    ->append(new Response(200, [], json_encode(['invoices' => ['id' => '1245', 'id' => '1247']])))
    ->append(new Response(404));
```

### Caveats

[](#caveats)

Currently, the guzzle mock doesn't assert or check anything regarding what requests you are making - it's just a simple way to test your code's reaction to a particular response without having to actually transmit a request to the remote API.

Support
-------

[](#support)

If you are having general issues with this repository, please contact us via the [SavvyWombat](https://savvywombat.com/contact) website.

Please report issues using the [GitHub issue tracker](https://github.com/SavvyWombat/laravel-test-utils/issues). You are also welcome to fork the repository and submit a pull request.

If you're using this repository, we'd love to hear your thoughts. Thanks!

Licence
-------

[](#licence)

This package is licensed under [The MIT License (MIT)](https://github.com/SavvyWombat/laravel-test-utils/blob/master/LICENSE).

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~169 days

Total

5

Last Release

2063d ago

PHP version history (2 changes)0.2PHP ^7.0

0.4PHP ^7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/949f4b63b47c6f037d6ddd22ad3c34e67950655eb51a31d2b1f1205eac7005d7?d=identicon)[SavvyWombat](/maintainers/SavvyWombat)

---

Top Contributors

[![horuskol](https://avatars.githubusercontent.com/u/290549?v=4)](https://github.com/horuskol "horuskol (18 commits)")

---

Tags

testlaravelhelpersutilsutilitiessavvywombatsavvy wombat

### Embed Badge

![Health badge](/badges/savvywombat-laravel-test-utils/health.svg)

```
[![Health](https://phpackages.com/badges/savvywombat-laravel-test-utils/health.svg)](https://phpackages.com/packages/savvywombat-laravel-test-utils)
```

###  Alternatives

[letsdrink/ouzo-goodies

Utility classes, test assertions and mocking framework extracted from Ouzo framework.

132617.9k7](/packages/letsdrink-ouzo-goodies)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
