PHPackages                             bit-mx/saloon-response-factories - 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. bit-mx/saloon-response-factories

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

bit-mx/saloon-response-factories
================================

Test saloon requests easily

3.0.0(1mo ago)1855MITPHPPHP ^8.3 || ^8.4 || ^8.5

Since Apr 15Pushed 1mo agoCompare

[ Source](https://github.com/bit-mx/saloon-response-factories)[ Packagist](https://packagist.org/packages/bit-mx/saloon-response-factories)[ RSS](/packages/bit-mx-saloon-response-factories/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (5)Dependencies (22)Versions (7)Used By (0)

Saloon Response Factories
=========================

[](#saloon-response-factories)

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Requirements](#requirements)
- [Use](#use)
- [Headers](#headers)
- [Status](#status)
- [Create a new factory](#create-a-new-factory)

### Installation

[](#installation)

You can install the package via composer:

```
composer require bitmx/saloon-response-factories
```

### Requirements

[](#requirements)

This package requires Laravel 10.0 or higher and PHP 8.1 or higher.

### Use

[](#use)

You can use factories to create fake data for your Saloon tests

To create a factory you should extend the SaloonResponseFactory class and implement the definition method.

```
namespace Tests\SaloonResponseFactories;

use BitMx\SaloonResponseFactories\Factories\SaloonResponseFactory;

class PostResponseFactoryFactory extends SaloonResponseFactory
{
    /**
     * {@inheritDoc}
     */
    public function definition(): array
    {
        return [
            'id' => $this->faker->unique()->randomNumber(),
            'title' => $this->faker->sentence(),
            'content' => $this->faker->paragraph(),
        ];
    }
}
```

You can use the faker property to generate fake data.

```
use Tests\SaloonResponseFactories\PostResponseFactoryFactory;

it('should get the post', function () {
    Saloon::fake([
        GetPostsRequest::class => PostResponseFactoryFactory::new()->create(),
    ]);
});
```

### Wrapping the response

[](#wrapping-the-response)

You can use the wrap method to wrap the response in a custom structure.

```
namespace Tests\SaloonResponseFactories;

use BitMx\SaloonResponseFactories\Factories\SaloonResponseFactory;

class PostResponseFactoryFactory extends SaloonResponseFactory
{
    /**
     * {@inheritDoc}
     */
    public function definition(): array
    {
        return [
            'id' => $this->faker->unique()->randomNumber(),
            'title' => $this->faker->sentence(),
            'content' => $this->faker->paragraph(),
        ];
    }

    public function wrap(): string
    {
        return 'data';
    }
}
```

This create a response like this:

```
\Saloon\Http\Faking\MockResponse::make([
    'data' => [
        'id' => 1,
        'title' => 'Title 1',
        'content' => 'Content 1',
    ],
]);
```

### Metadata

[](#metadata)

You can use the metadata method to add metadata to the response.

```
namespace Tests\SaloonResponseFactories;

use BitMx\SaloonResponseFactories\Factories\SaloonResponseFactory;

class PostResponseFactoryFactory extends SaloonResponseFactory
{
    /**
     * {@inheritDoc}
     */
    public function definition(): array
    {
        return [
            'id' => $this->faker->unique()->randomNumber(),
            'title' => $this->faker->sentence(),
            'content' => $this->faker->paragraph(),
        ];
    }

    public function wrap(): string{
        return 'data';
    }

    public function metadata(): array
    {
        return [
            'total' => 10,
        ];
    }
}
```

This creates a response like this:

```
\Saloon\Http\Faking\MockResponse::make([
    'data' => [
        'id' => 1,
        'title' => 'Title 1',
        'content' => 'Content 1',
    ],
    'metadata' => [
        'total' => 10,
    ],
]);
```

### Count

[](#count)

You can also use the count method to create an array of fake data.

```
use Tests\SaloonResponseFactories\PostResponseFactoryFactory;

it('should get the post', function () {
    Saloon::fake([
        GetPostsRequest::class => PostResponseFactoryFactory::new()->count(5)->create(),
    ]);
});
```

This code create a MockResponse like this:

```
\Saloon\Http\Faking\MockResponse::make([
    [
        'id' => 1,
        'title' => 'Title 1',
        'content' => 'Content 1',
    ],
    [
        'id' => 2,
        'title' => 'Title 2',
        'content' => 'Content 2',
    ],
    [
        'id' => 3,
        'title' => 'Title 3',
        'content' => 'Content 3',
    ],
    [
        'id' => 4,
        'title' => 'Title 4',
        'content' => 'Content 4',
    ],
    [
        'id' => 5,
        'title' => 'Title 5',
        'content' => 'Content 5',
    ],
]);
```

You can use the state method to change the default values of the factory.

```
it('should get the post', function () {
    Saloon::fake([
        GetPostsRequest::class => PostResponseFactoryFactory::new()->state([
            'title' => 'Custom Title',
        ])->create(),
    ]);
});
```

Or create a new method in the factory to change the default values.

```
namespace Tests\SaloonResponseFactories;

use BitMx\SaloonResponseFactories\Factories\SaloonResponseFactory;

class PostResponseFactoryFactory extends SaloonResponseFactory
{
    /**
     * {@inheritDoc}
     */
    public function definition(): array
    {
        return [
            'id' => $this->faker->unique()->randomNumber(),
            'title' => $this->faker->sentence(),
            'content' => $this->faker->paragraph(),
        ];
    }

    public function withCustomTitle(): self
    {
        return $this->state([
            'title' => 'Custom Title',
        ]);
    }
}
```

```
se Tests\SaloonResponseFactories\PostResponseFactoryFactory;

it('should get the post', function () {
    Saloon::fake([
        GetPostsRequest::class => PostResponseFactoryFactory::new()->withCustomTitle()->create(),
    ]);
});
```

Headers
-------

[](#headers)

You can use the headers method to add headers to the response.

```
namespace Tests\SaloonResponseFactories;

use BitMx\SaloonResponseFactories\Factories\SaloonResponseFactory;

class PostResponseFactoryFactory extends SaloonResponseFactory
{
    /**
     * {@inheritDoc}
     */
    public function definition(): array
    {
        return [
            'id' => $this->faker->unique()->randomNumber(),
            'title' => $this->faker->sentence(),
            'content' => $this->faker->paragraph(),
        ];
    }

    public function withCustomTitle(): self
    {
        return $this->state([
            'title' => 'Custom Title',
        ]);
    }

    public function withHeaders(): self
    {
        return $this->headers([
            'X-Custom-Header' => 'Custom Value',
        ]);
    }
}
```

```
use Tests\SaloonResponseFactories\PostResponseFactoryFactory;

it('should get the post', function () {
    Saloon::fake([
        GetPostsRequest::class => PostResponseFactoryFactory::new()->withHeaders()->create(),
    ]);
});
```

You can also use the headers method to add multiple headers.

```
namespace Tests\SaloonResponseFactories;

use Tests\SaloonResponseFactories\PostResponseFactoryFactory;

it('should get the post', function () {
    Saloon::fake([
        GetPostsRequest::class => PostResponseFactoryFactory::new()->headers([
            'X-Custom-Header' => 'Custom Value',
            'X-Another-Header' => 'Another Value',
        ])->create(),
    ]);
});
```

Status
------

[](#status)

You can use the status method to change the status code of the response.

```
use Tests\SaloonResponseFactories\PostResponseFactoryFactory;

it('should get the post', function () {
    Saloon::fake([
        GetPostsRequest::class => PostResponseFactoryFactory::new()->status(404)->create(),
    ]);
});
```

### Create a new factory

[](#create-a-new-factory)

You can create a new factory using the artisan command.

```
php artisan make:saloon-response-factory PostResponseFactory
```

This command will create a new factory in the `tests/SaloonResponseFactories` directory.

###  Health Score

48

—

FairBetter than 94% of packages

Maintenance90

Actively maintained with recent releases

Popularity19

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity63

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

Total

5

Last Release

49d ago

Major Versions

1.0.2 → 2.0.02025-06-27

2.0.0 → 3.0.02026-05-09

PHP version history (3 changes)1.0.0PHP ^8.1 || ^8.2 || ^8.3

2.0.0PHP ^8.2 || ^8.3 || ^8.4

3.0.0PHP ^8.3 || ^8.4 || ^8.5

### Community

Maintainers

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

---

Top Contributors

[![jenriquez-bit](https://avatars.githubusercontent.com/u/44071711?v=4)](https://github.com/jenriquez-bit "jenriquez-bit (6 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/bit-mx-saloon-response-factories/health.svg)

```
[![Health](https://phpackages.com/badges/bit-mx-saloon-response-factories/health.svg)](https://phpackages.com/packages/bit-mx-saloon-response-factories)
```

###  Alternatives

[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k51.0M7.6k](/packages/larastan-larastan)[laravel/ai

The official AI SDK for Laravel.

9782.1M162](/packages/laravel-ai)[tallstackui/tallstackui

TallStackUI is a powerful suite of Blade components that elevate your workflow of Livewire applications.

721160.4k12](/packages/tallstackui-tallstackui)[saloonphp/laravel-plugin

The official Laravel plugin for Saloon

806.6M187](/packages/saloonphp-laravel-plugin)[calebdw/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

15104.9k4](/packages/calebdw-larastan)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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