PHPackages                             laragear/meta-testing - 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. laragear/meta-testing

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

laragear/meta-testing
=====================

A Laravel Package helper for Laravel Packages

v4.2.0(3mo ago)319.3k↑25%110MITPHPPHP ^8.3CI passing

Since Feb 18Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/Laragear/MetaTesting)[ Packagist](https://packagist.org/packages/laragear/meta-testing)[ Fund](https://github.com/sponsors/DarkGhostHunter)[ Fund](https://paypal.me/darkghosthunter)[ RSS](/packages/laragear-meta-testing/feed)WikiDiscussions 4.x Synced 3d ago

READMEChangelog (10)Dependencies (3)Versions (31)Used By (10)

Meta Testing
============

[](#meta-testing)

[![Latest Version on Packagist](https://camo.githubusercontent.com/61ac7056eb1d95489ff1fbd7dcfa95a2ebb32fd3546728e6f92a6ca9c72850ea/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c617261676561722f6d6574612d74657374696e672e737667)](https://packagist.org/packages/laragear/meta-testing)[![Latest stable test run](https://github.com/Laragear/MetaTesting/workflows/Tests/badge.svg)](https://github.com/Laragear/MetaTesting/actions)[![Codecov coverage](https://camo.githubusercontent.com/410a30338441f2bcf256a6b95d37e6695ee2f1f13cdd02501b0b590185f34f28/68747470733a2f2f636f6465636f762e696f2f67682f4c617261676561722f4d65746154657374696e672f67726170682f62616467652e7376673f746f6b656e3d626f6758617037526a6e)](https://codecov.io/gh/Laragear/MetaTesting)[![Maintainability](https://camo.githubusercontent.com/6d29de61187dd1b3379ad808086d4fd75d7e876ffeaf066968145acfe295c33f/68747470733a2f2f716c74792e73682f6261646765732f32636631376361642d323934362d343536372d396562332d6265346239376439663830342f6d61696e7461696e6162696c6974792e737667)](https://qlty.sh/gh/Laragear/projects/MetaTesting)[![Sonarcloud Status](https://camo.githubusercontent.com/0c7796cb0ca885cce7e32f8871f47bdc281181d6f995b2de182e9bc39ece6815/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d4c617261676561725f4d65746154657374696e67266d65747269633d616c6572745f737461747573)](https://sonarcloud.io/dashboard?id=Laragear_MetaTesting)[![Laravel Octane Compatibility](https://camo.githubusercontent.com/70359a356da237cd29561bc5d0bb80baae775b5ff62f288ed324755382858342/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2532304f6374616e652d436f6d70617469626c652d737563636573733f7374796c653d666c6174266c6f676f3d6c61726176656c)](https://laravel.com/docs/11.x/octane#introduction)

A Laravel Package for testing Laravel Packages.

```
public function test_has_service_registered(): void
{
    $this->assertHasServices('my-cool-service');
}
```

Become a sponsor
----------------

[](#become-a-sponsor)

[![](.github/assets/support.png)](https://github.com/sponsors/DarkGhostHunter)

Your support allows me to keep this package free, up-to-date and maintainable. Alternatively, you can **spread the word on social media**

Requirements
------------

[](#requirements)

- PHP 8.3 or later
- Laravel 12 or later.

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

[](#installation)

Require this package into your project using Composer:

```
composer require --dev laragear/meta-testing
```

Caution

**DO NOT** install this package outside `require-dev`, unless you plan to use this package in production environments.

Testing
-------

[](#testing)

### Testing the Service Provider

[](#testing-the-service-provider)

The `InteractsWithServiceProvider` allows to quickly test if the Service Provider of your package has registered all the needed bits of code into the Service Container.

```
use Orchestra\Testbench\TestCase
use Laragear\MetaTesting\InteractsWithServiceProvider;

class ServiceProviderTest extends TestCase
{
    use InteractsWithServiceProvider;

    public function test_is_registered_as_singleton(): void
    {
        $this->assertHasSingletons(\Vendor\Package\MyService::class);
    }
}
```

The available assertions are in this table:

MethodDescription`assertHasDriver()`Assert a service as registered given driver name`assertHasServices()`Assert services have been registered into the Service Container`assertHasSingletons()`Assert services have been registered as a shared instance into the Service Container`assertHasAlias()`Assert a service has been registered with the issued alias`assertConfigMerged()`Assert the library configuration file has been merged into the application.`assertPublishes()`Assert the library publishes the paths into the application`assertPublishesMigrations()`Assert the library publishes the migrations into the application`assertHasTranslations()`Assert the library translations have been registered into the translator`assertHasViews()`Assert the library views have been registered into the view compiler`assertHasBladeComponent()`Assert the library Blade Components have been registered into the view compiler`assertHasBladeDirectives()`Assert the library Blade Directives have been registered into the view compiler`assertHasValidationRules()`Assert the library Validation Rules have been registered into the validator`assertRouteByName()`Assert the library Routes names have been registered into the router`assertRouteByUri()`Assert the library Routes URIs have been registered into the router`assertRouteByAction()`Assert the library Routes actions have been registered into the router`assertHasMiddlewareAlias()`Assert the library Middleware alias has been registered into the router`assertHasGlobalMiddleware()`Assert the library Middleware have been registered globally into the router`assertHasMiddlewareInGroup()`Assert the library Middleware have been registered into a middleware group`assertGateHasAbility()`Assert the library abilities have been registered into the authorization gate`assertGateHasPolicy()`Assert the library policies have been registered into the authorization gate`assertHasCommand()`Assert the library commands aliases have been registered into the application console`assertHasCommandParameters()`Assert the library command has the given options and/or arguments.`assertHasScheduledTask()`Assert the library scheduled tasks have been registered into the scheduler`assertScheduledTaskRunsAt()`Assert the library scheduled tasks runs at a given moment`assertHasListeners()`Assert the library has registered listeners for the issued event`assertHasMacro()`Assert the library macros are registered into the target Macroable class### Service Helpers

[](#service-helpers)

The `InteractsWithServices` trait includes helpers to retrieve services from the Service Container and do quick things like checks or preparation.

```
public function test_something_important(): void
{
    // Get a service from the Service Container, optionally run over a callback.
    $cache = $this->service('cache', fn ($cache) => $cache->set('foo', 'bar', 30));

    // Run a service once and forgets it, while running a callback over it.
    $compiler = $this->serviceOnce('blade.compiler', fn($compiler) => $compiler->check('cool'));

    // Executes a callback over a REAL service when already mocked.
    $this->unmock('files', function ($files): void {
        $files->copyDirectory('foo', 'bar');
    });
}
```

### Validation

[](#validation)

This meta-package includes a `InteractsWithValidator` trait, that assert if a rule passes or fails using minimal data. This is useful when creating validation rules and testing them without too much boilerplate.

```
use Laragear\MetaTesting\Validation\InteractsWithValidator;

public function test_validation_rule(): void
{
    // Assert the validation rule passes.
    $this->assertValidationPasses(['test' => 'foo'],['test' => 'my_rule']);

    // Assert the validation rule fails.
    $this->assertValidationFails(['test' => 'bar'],['test' => 'my_rule']);
}
```

### Middleware

[](#middleware)

You can test any middleware easily using the `InteractsWithMiddleware` trait and its `middleware()` method. It creates an on-demand route for the given path before sending a test Request to it, so there is no need to register a route.

```
use Illuminate\Http\Request;
use Vendor\Package\Http\Middleware\MyMiddleware;
use Laragear\MetaTesting\Http\Middleware\InteractsWithMiddleware;

public function test_middleware(): void
{
    $response = $this->middleware(MyMiddleware::class)->using(function (Request $request) {
        // ...
    })->post('test', ['foo' => 'bar']);

    $response->assertOk();
}
```

It proxies all `MakesHttpRequest` trait methods, like `get()` or `withUnencryptedCookie()`, so you can get creative with testing your middleware.

```
$this->middleware(MyMiddleware::class, 'test_argument')
    ->withUnencryptedCookie()
    ->be($this->myTestUser)
    ->post('test/route', ['foo' => 'bar'])
    ->assertSee('John');
```

### Form Request

[](#form-request)

You can test a Form Request if it passes authorization a validation using different data using the `InteractsWithFormRequests` trait. The `formRequest()` requires the Form Request class, and an `array` with the data to include in the request, to test in isolation.

```
public function test_form_request()
{
    $this->formRequest(MyFormRequest::class, ['foo' => 'bar'])->assertOk();
}
```

### Authorization

[](#authorization)

To check if a policy or gate works appropriately, use the `InteractsWithAuthorization` trait to check whether a user *can* or *cannot* be authorized to a given action.

```
public function test_authorization()
{
    $admin = User::factory()->admin()->create();

    $this->assertUserCan($admin, 'viewDashboard');
}
```

### Casts

[](#casts)

The `InteractsWithCast` trait allows to quickly test if a cast sets values from an attribute appropriately, and can return a given value from an attribute value. It also supports checking on multiple attributes at a time.

```
public function test_cast()
{
    $this->cast(MyTestCast::class)
        ->assertCastFrom(null, new Cast)
        ->assertCastTo('{"foo":"bar"}', new Cast(['foo' => 'bar']));
}
```

### Eloquent Builder

[](#eloquent-builder)

Tip

The Eloquent Builder is only available for Laravel v11.15.0 and later.

To mock the Eloquent Builder of a Model, you may use the `InteractsWithEloquentBuilder` trait and use the `mockQueryFor()` method to make expectations on the builder itself by just calling the methods to chain.

To break the chain, you may use `and()` with the final method to call and the results you want to return through the `andReturn()` or `andReturnUsing()`.

```
use App\Models\User;

public function test_builder()
{
    $this->mockQueryFor(User::class)->whereKey(1)->and()->get()->shouldReturn(null);

    $result = User::query()->whereKey(1)->get();

    $this->assertNull($result);
}
```

Alternatively, you may use a function to alter the Builder mock expectations directly, or use the `mock()` helper.

```
use App\Models\User;
use Mockery\MockInterface;

public function test_builder()
{
    $this->mockQueryFor(User::class, function (MockInterface $mock) {
        $mock->expects('find', 1)->andReturnNull();
    });

    $this->assertNull(User::find(1));
}
```

To restore the original Eloquent Builder, you can use `unmockQueryFor($model)` anywhere in your code. For example, it can be part of the last expectation so its restored after a given method call.

```
use App\Models\User;
use Mockery\MockInterface;
use Laragear\MetaTesting\Eloquent\PendingBuilderTestProxy;

public function test_builder()
{
    // $mock = $this->mockQueryFor(User::class)->mock();

    $this->mockQueryFor(User::class, function (MockInterface $mock) {
        $mock->expects('find', 1)->andReturnUsing(function () {
            $this->unmockQueryFor(User::class);

            return null;
        });;
    });

    $this->assertNull(User::find(1));

    $this->assertNotNull(User::find(1))
}
```

### Pipeline

[](#pipeline)

The `InteractsWithPipeline` trait allows to test and ensure pipes on the pipelines work as expected.

You may use this to test pipelines as a whole, ensuring the pipe order never changes, or test pipes in isolation by mocking services it requires to work. Alternatively, you may also mock the *passable* to test if some methods are called.

```
public function test_pipeline()
{
    $pipeline = $this->pipeline(MyPipeline::class)
        // Check the order of pipes
        ->assertPipes([
            FirstPipe::class,
            SecondPipe::class,
            ThirdPipe::class,
        ])
        // Check all pipes have their handler method.
        ->assertVia('handle');

    // Mock the pipeline to be used elsewhere in your application
    $pipeline->mock(function ($mock) {
        $mock->expects('send')->andReturnSelf();
    })

    // Test the passable through all pipes and assert its result.
    $pipeline->send(new Passable(['value' => 10]))
        ->assertPassable(function (Passable $passable) {
            return $passable->value === 130;
        })

    // Test a pipe in isolation and assert the results.
    $pipeline->isolatePipe(SecondClass::class)
        ->send(new Passable(['value' => 10]))
        ->assertPassable(function (Passable $passable) {
            return $passable->value === 100;
        });

    // Mock services a pipe or pipeline requires, or mock the passable.
    $pipeline->isolatePipe(FirstPipe::class)
        ->withMockedService(MyService::class, function ($mock) {
            $mock->expects('sum')->with(0)->andReturn(10);
        })
        ->sendMock(Passable::class, function ($mock) {
            $mock->expects('set')->with(true)->andReturn(10);
        });
}
```

Laravel Octane compatibility
----------------------------

[](#laravel-octane-compatibility)

- There are no singletons using a stale application instance.
- There are no singletons using a stale config instance.
- There are no singletons using a stale request instance.
- There are no static properties being written.

There should be no problems using this package with Laravel Octane.

Security
--------

[](#security)

If you discover any security-related issues, issue a [Security Advisory](https://github.com/Laragear/Banpay/security/advisories/new).

License
=======

[](#license)

This specific package version is licensed under the terms of the [MIT License](LICENSE.md), at the time of publishing.

[Laravel](https://laravel.com) is a Trademark of [Taylor Otwell](https://github.com/TaylorOtwell/). Copyright © 2011-2026 Laravel LLC.

###  Health Score

53

—

FairBetter than 96% of packages

Maintenance82

Actively maintained with recent releases

Popularity29

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity71

Established project with proven stability

 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 ~54 days

Recently: every ~62 days

Total

22

Last Release

96d ago

Major Versions

1.x-dev → v2.0.02024-03-13

v2.0.1 → v3.0.02025-02-16

v3.5.0 → v4.0.02026-03-03

PHP version history (4 changes)v1.0.0PHP 8.\*

v1.1.0PHP ^8.1

v3.0.0PHP ^8.2

v4.0.0PHP ^8.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5141911?v=4)[Italo](/maintainers/DarkGhostHunter)[@DarkGhostHunter](https://github.com/DarkGhostHunter)

---

Top Contributors

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

---

Tags

laravellibrarieslibrarymetapackagepackagesphptesttestingtestinglaravelpackagelibrarymeta

### Embed Badge

![Health badge](/badges/laragear-meta-testing/health.svg)

```
[![Health](https://phpackages.com/badges/laragear-meta-testing/health.svg)](https://phpackages.com/packages/laragear-meta-testing)
```

###  Alternatives

[nunomaduro/laravel-mojito

A lightweight package for testing Laravel views.

369461.8k12](/packages/nunomaduro-laravel-mojito)[davestewart/sketchpad

An innovative front-end environment for interactive Laravel development

29512.9k1](/packages/davestewart-sketchpad)[guanguans/laravel-soar

SQL optimizer and rewriter for laravel. - laravel 的 SQL 优化器和重写器。

2248.4k](/packages/guanguans-laravel-soar)[hyvor/laravel-playwright

Laravel and Playwright E2E Testing

3419.9k](/packages/hyvor-laravel-playwright)[mominalzaraa/filament-localization

The first and only automatic Filament localization package with intelligent resource scanning, structured translation files, and comprehensive testing

102.8k](/packages/mominalzaraa-filament-localization)[srlabs/laravel-testing-utilities

Helper utilities for testing Laravel Applications

1011.9k](/packages/srlabs-laravel-testing-utilities)

PHPackages © 2026

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