Skip to content

Test a Pulsar application

Unit-test atomic Domain work, integration-test UseCases, bindings, and lifecycles, feature-test adapters, and use the package preset for structural rules. The smallest suitable test is recommended, provided it keeps the framework behavior being proved.

Before you begin

Run composer run reference:test and vendor/bin/pest tests/Integration/BootstrapIntegrationTest.php in core.

Prove durable delivery behavior

examples/reference-app/tests/Outbox/TransactionalOutboxTest.php — Atomic outbox and retry-deduplicated inbox evidence.

php
<?php

namespace Tests\Outbox;

use App\Models\User;
use App\Pulsar\Domain\Orders\DTOs\CreateOrderData;
use App\Pulsar\Services\Client\Modules\Orders\UseCases\PlaceOrder;
use App\Pulsar\Services\Internal\Modules\Orders\UseCases\RelayOutbox;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class TransactionalOutboxTest extends TestCase
{
    use RefreshDatabase;

    // #region transactional-outbox-test
    public function test_outbox_write_is_atomic_and_the_inbox_deduplicates_relay_retry(): void
    {
        User::factory()->create(['tenant_id' => 'tenant-outbox']);
        $order = app(PlaceOrder::class)->execute(new CreateOrderData('tenant-outbox', 'outbox-1', 100));
        $key = 'order-placed-'.$order->id;
        $this->assertDatabaseHas('outbox_messages', ['idempotency_key' => $key]);
        $this->assertTrue(app(RelayOutbox::class)->execute($key));
        $this->assertFalse(app(RelayOutbox::class)->execute($key));
        $this->assertDatabaseCount('inbox_messages', 1);
    }
    // #endregion
}

Verify and troubleshoot

Use fakes for mail, notification, queue, and Contracts; use real container and database integration for lifecycle and transaction claims. The preset enforces structural core only; behavioral rules such as no UseCase-to-UseCase calls still require review and focused tests.