PHPackages                             amirrezam75/laravel-assertions - 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. amirrezam75/laravel-assertions

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

amirrezam75/laravel-assertions
==============================

A set of helpful assertions when testing Laravel applications.

1.0.0(3y ago)27MITPHPPHP &gt;=7.3|^8.0

Since Sep 22Pushed 3y ago1 watchersCompare

[ Source](https://github.com/AmirRezaM75/laravel-assertions)[ Packagist](https://packagist.org/packages/amirrezam75/laravel-assertions)[ RSS](/packages/amirrezam75-laravel-assertions/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

Installation
------------

[](#installation)

`composer require amirrezam75/laravel-assertions`

assertRedirection
-----------------

[](#assertredirection)

I was working on a project and in order to test oauth2 redirection, I ended up with something like this:

**Before**

```
$response = $this->get('integrations/calendars?provider=GOOGLE')
            ->assertStatus(302);

$location = $response->headers->get('location');
$query = parse_url($location, PHP_URL_QUERY);
parse_str($query, $params);

$this->assertEquals(secure_url('integrations/calendars/callback'), $params['redirect_uri']);
$this->assertStringContainsString('https://accounts.google.com/o/oauth2/auth', $location);
$this->assertEquals('https://www.googleapis.com/auth/calendar', $params['scope']);
$this->assertEquals(config('services.google.client_id'), $params['client_id']);
$this->assertEquals('true', $params['include_granted_scopes']);
$this->assertEquals('offline', $params['access_type']);
$this->assertEquals('code', $params['response_type']);
$this->assertTrue(strlen($params['state']) === 40);
$this->assertEquals('consent', $params['prompt']);

```

I think it would be cleaner and much more readable if have something similar to `AssertableJson` class.

**After**

```
$response = $this->get('integrations/calendars?provider=GOOGLE')
    ->assertRedirection(function (AssertableUri $uri) {
        $uri
            ->whereQuery('redirect_uri', secure_url('integrations/calendars/callback'))
            ->whereQuery('scope', 'https://www.googleapis.com/auth/calendar')
            ->whereQuery('client_id', config('services.google.client_id'))
            ->whereQuery('include_granted_scopes', 'true')
            ->whereQuery('access_type', 'offline')
            ->whereQuery('response_type', 'code')
            ->whereQuery('prompt', 'consent')
            ->whereQuery('state', function($state) {
                return strlen($state) === 40;
            });

    });

```

We can assert other parts of URI using these methods:

- whereFragment($value)
- whereHost($value)
- wherePass($value)
- wherePath($value)
- wherePort($value)
- whereScheme($value)
- whereUser($value)

IMO It's not practical but we can only check for existence of component using these methods:

- hasFragment()
- hasHost()
- hasPass()
- hasPath()
- hasPort()
- hasScheme()
- hasUser()

### `etc()`

[](#etc)

Like AssertableJson it uses `Interaction` trait, this will automatically fail your test when you haven't interacted with at least one of the props in a **URI query string**. Hence the sequence is fixed in other parts of URI; they don't need to be affected by interacted method and can be asserted using `assertRedirectContains` method.

```
$assert = new AssertableUri('https://foo.bar?name=Taylor&id=1');
        $assert->whereQuery('name', 'Taylor')
            ->etc() // If remove this line, this will fail
            ->interacted();

```

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

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

Unknown

Total

1

Last Release

1326d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3f0eaa55b5f55b0edacfc514ff3d4fe7d45da3e89475a4d8247e3c8d0720f370?d=identicon)[amirrezam75](/maintainers/amirrezam75)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/amirrezam75-laravel-assertions/health.svg)

```
[![Health](https://phpackages.com/badges/amirrezam75-laravel-assertions/health.svg)](https://phpackages.com/packages/amirrezam75-laravel-assertions)
```

###  Alternatives

[jasonmccreary/laravel-test-assertions

A set of helpful assertions when testing Laravel applications.

3513.9M32](/packages/jasonmccreary-laravel-test-assertions)[timacdonald/log-fake

A drop in fake logger for testing with the Laravel framework.

4235.9M55](/packages/timacdonald-log-fake)[ergebnis/phpunit-slow-test-detector

Provides facilities for detecting slow tests in phpunit/phpunit.

1468.1M72](/packages/ergebnis-phpunit-slow-test-detector)[typo3/testing-framework

The TYPO3 testing framework provides base classes for unit, functional and acceptance testing.

675.0M774](/packages/typo3-testing-framework)[robiningelbrecht/phpunit-pretty-print

Prettify PHPUnit output

76460.0k15](/packages/robiningelbrecht-phpunit-pretty-print)[webmozarts/strict-phpunit

Enables type-safe comparisons of objects in PHPUnit

31252.7k5](/packages/webmozarts-strict-phpunit)

PHPackages © 2026

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