clear(); }); it('searches and finds clients matching query with pagination', function () use ($repository): void { // GIVEN $client1 = Client::hydrate( id: new ClientId(Uuid::uuid7()), name: new ClientName('Production Gateway'), identifier: new ClientIdentifier('arcadia_id_' . str_repeat('a', 32)), secret: new ClientSecret('arcadia_sec_' . str_repeat('1', 86)), isActive: true, updatedAt: new \DateTimeImmutable(), ); $client2 = Client::hydrate( id: new ClientId(Uuid::uuid7()), name: new ClientName('Staging Hub'), identifier: new ClientIdentifier('arcadia_id_' . str_repeat('b', 32)), secret: new ClientSecret('arcadia_sec_' . str_repeat('2', 86)), isActive: false, updatedAt: new \DateTimeImmutable(), ); $repository->add($client1, $client2); $usecase = new FindClient($repository); // WHEN $resultByName = $usecase->execute(new Input('production', Pagination::ofOffsetAndLimit(0, 10))); $resultByIdentifier = $usecase->execute(new Input('arcadia_id_' . str_repeat('b', 32))); $resultBySlug = $usecase->execute(new Input('staging-hub')); // THEN expect($resultByName)->toBeInstanceOf(Output::class) ->and($resultByName->clients)->toBeInstanceOf(Paginated::class) ->and($resultByName->clients->getTotal())->toBe(1) ->and($resultByName->clients->getItems()[0]->name->value)->toBe('Production Gateway') ->and($resultByIdentifier->clients->getTotal())->toBe(1) ->and($resultByIdentifier->clients->getItems()[0]->name->value)->toBe('Staging Hub') ->and($resultBySlug->clients->getTotal())->toBe(1) ->and($resultBySlug->clients->getItems()[0]->name->value)->toBe('Staging Hub'); }); it('throws InvalidArgumentException when query is empty', function (): void { // GIVEN & WHEN & THEN expect(fn () => new Input(' ')) ->toThrow(\InvalidArgumentException::class, 'Search query cannot be empty.'); }); it('returns empty paginated result when no clients match', function () use ($repository): void { // GIVEN $usecase = new FindClient($repository); // WHEN $result = $usecase->execute(new Input('non-existent')); // THEN expect($result->clients)->toBeInstanceOf(Paginated::class) ->and($result->clients->getTotal())->toBe(0) ->and($result->clients->getItems())->toBeEmpty(); }); });