<?php

use App\Provisioning\PipelineRegistry;
use Tests\Support\Steps\FakeAdvanceStep;
use Tests\Support\Steps\FakeRetryStep;

it('resolves step instances by index', function () {
    $registry = new PipelineRegistry(['host' => [FakeAdvanceStep::class, FakeRetryStep::class]]);

    expect($registry->count('host'))->toBe(2)
        ->and($registry->resolve('host', 0))->toBeInstanceOf(FakeAdvanceStep::class)
        ->and($registry->resolve('host', 1))->toBeInstanceOf(FakeRetryStep::class);
});

it('throws for an unknown pipeline', function () {
    (new PipelineRegistry([]))->stepsFor('nope');
})->throws(InvalidArgumentException::class);

it('throws for an out-of-range step index', function () {
    (new PipelineRegistry(['host' => [FakeAdvanceStep::class]]))->resolve('host', 5);
})->throws(InvalidArgumentException::class);
