artisan('client:create') // THEN ->expectsQuestion('Client name (e.g. "Production Gateway")', $clientName) ->expectsConfirmation('Create this API client?', 'yes') ->expectsOutputToContain("API client '{$clientName}' created successfully.") ->expectsOutputToContain('Store the secret securely') ->assertSuccessful(); $client = ApiClient::query()->where('name', $clientName)->first(); expect($client)->not->toBeNull() ->and($client->is_active)->toBeTrue() ->and($client->name->value)->toBe($clientName) ->and((string) $client->identifier->value)->toStartWith('arcadia_id_') ->and((string) $client->secret->value)->toStartWith('arcadia_sec_'); }); it('aborts when user cancels confirmation', function (): void { // GIVEN /** @var \Tests\TestCase $this */ $clientName = 'Cancelled Gateway'; // WHEN $this->artisan('client:create') // THEN ->expectsQuestion('Client name (e.g. "Production Gateway")', $clientName) ->expectsConfirmation('Create this API client?', 'no') ->expectsOutput('Client creation cancelled.') ->assertSuccessful(); $client = ApiClient::query()->where('name', $clientName)->first(); expect($client)->toBeNull(); }); it('retries when an empty name is provided', function (): void { // GIVEN /** @var \Tests\TestCase $this */ $this->artisan('client:create') ->expectsQuestion('Client name (e.g. "Production Gateway")', '') ->expectsOutput('Client name cannot be empty.') ->expectsQuestion('Client name (e.g. "Production Gateway")', 'Valid Gateway') // WHEN ->expectsConfirmation('Create this API client?', 'yes') ->expectsOutputToContain("API client 'Valid Gateway' created successfully.") // THEN ->assertSuccessful(); $client = ApiClient::query() ->where('name', 'Valid Gateway') ->first(); expect($client)->not->toBeNull(); }); it('fails after maximum retries with invalid names', function (): void { // GIVEN /** @var \Tests\TestCase $this */ $this->artisan('client:create') // WHEN ->expectsQuestion('Client name (e.g. "Production Gateway")', '') ->expectsOutput('Client name cannot be empty.') ->expectsQuestion('Client name (e.g. "Production Gateway")', '') ->expectsOutput('Client name cannot be empty.') ->expectsQuestion('Client name (e.g. "Production Gateway")', '') ->expectsOutput('Client name cannot be empty.') ->expectsOutput('Maximum number of attempts reached. Aborting.') // THEN ->assertFailed(); }); });