# Testing

**Package:** Laravel Compose | **Version:** 1 | **URL:** https://mozex.dev/docs/laravel-compose/v1/operating/testing

---

## Faking the manager

`Compose::fake()` swaps the manager for one that records redeploys instead of running them. An enabled stack records `Redeployed`, a disabled one `Skipped`, and no env file is written and no docker command runs. It also calls `Process::fake()`, so a stack's `status()`, `logs()`, or `exec()` never reach a daemon either. When a test needs specific process results as well, call `Process::fake([...])` before `Compose::fake()`: an existing fake is kept, but a bare one installed first would shadow patterns you add afterwards.

```php
use Mozex\Compose\Facades\Compose;

it('redeploys the search stack after a deploy', function (): void {
    $fake = Compose::fake();

    $this->artisan('deploy:after')->assertSuccessful();

    $fake->assertRedeployed('meilisearch')
        ->assertSkipped('mailpit');
});
```

Assertions: `assertRedeployed($name)`, `assertSkipped($name)`, `assertNotRedeployed($name)`, `assertNothingRedeployed()`. `results()` returns the recorded `RedeployResult` per stack. `shouldFail($name)` makes the next redeploy of that stack report `Failed`, for testing the code that reacts to one.

## Faking the processes only

When you want the real recipe to run against a fake daemon, use `Process::fake()` directly. Every docker invocation goes through Laravel's `Process` facade with an array command, so `assertRan` sees the exact arguments:

```php
use Illuminate\Process\PendingProcess;
use Illuminate\Support\Facades\Process;

Process::fake();

Compose::redeploy('meilisearch');

Process::assertRan(fn (PendingProcess $process): bool => in_array('up', $process->command, true)
    && in_array('--wait', $process->command, true));
```

One thing to know about fake patterns: Symfony quotes every argument on Linux, so a pattern like `'*ps --format*'` matches on Windows and not on CI. Put `*` between tokens (`'*ps*--format*'`) or match on `$process->command` in a closure.

## Testing a stack class

A stack class is plain PHP. Test its `environment()` and `enabled()` against config the way you'd test anything that reads config:

```php
it('derives the port from the scout host', function (): void {
    config()->set('scout.meilisearch.host', 'http://127.0.0.1:7701');

    expect((new MeilisearchStack)->environment()['MEILISEARCH_PORT'])->toBe(7701);
});
```

And keep the stacks consistent with their compose files with the [doctor](https://mozex.dev/docs/laravel-compose/v1/deploying/doctor) report in an architecture test.

---

## Table of Contents

- [Introduction](https://mozex.dev/docs/laravel-compose/v1)
- [AI Integration](https://mozex.dev/docs/laravel-compose/v1/ai-integration)
- [Support Us](https://mozex.dev/docs/laravel-compose/v1/support-us)
- [Requirements](https://mozex.dev/docs/laravel-compose/v1/requirements)
- [Changelog](https://mozex.dev/docs/laravel-compose/v1/changelog)
- [Contributing](https://mozex.dev/docs/laravel-compose/v1/contributing)
- [Questions & Issues](https://mozex.dev/docs/laravel-compose/v1/questions-and-issues)
- [About Mozex](https://mozex.dev/docs/laravel-compose/v1/about)
- [Installation](https://mozex.dev/docs/laravel-compose/v1/installation)
- [Configuration](https://mozex.dev/docs/laravel-compose/v1/configuration)

### Stacks

- [Defining a Stack](https://mozex.dev/docs/laravel-compose/v1/stacks/defining-a-stack)
- [Discovery](https://mozex.dev/docs/laravel-compose/v1/stacks/discovery)
- [Environment Files](https://mozex.dev/docs/laravel-compose/v1/stacks/environment-files)
- [Compose Files](https://mozex.dev/docs/laravel-compose/v1/stacks/compose-files)

### Deploying

- [Redeploy](https://mozex.dev/docs/laravel-compose/v1/deploying/redeploy)
- [Hosting Platforms](https://mozex.dev/docs/laravel-compose/v1/deploying/hosting-platforms)
- [Remote Daemons](https://mozex.dev/docs/laravel-compose/v1/deploying/remote-daemons)
- [Doctor](https://mozex.dev/docs/laravel-compose/v1/deploying/doctor)

### Operating

- [Status, Logs, and Down](https://mozex.dev/docs/laravel-compose/v1/operating/status-logs-down)
- [Health Check](https://mozex.dev/docs/laravel-compose/v1/operating/health-check)
- [Events](https://mozex.dev/docs/laravel-compose/v1/operating/events)
- [Testing](https://mozex.dev/docs/laravel-compose/v1/operating/testing)

### Recipes

- [Meilisearch](https://mozex.dev/docs/laravel-compose/v1/recipes/meilisearch)
- [Telegram Bot API](https://mozex.dev/docs/laravel-compose/v1/recipes/telegram-bot-api)