assertCount(1, $results); $results = StepService::check([ RegisterOrLogin::class, Cart::class, RFF::class, ]); $this->assertCount(0, $results); $results = StepService::check([ RegisterOrLogin::class, RFF::class, Cart::class, ]); $this->assertCount(0, $results); } public function testSorting() { $results = $this->sort([ RFF::class, Methods::class, RegisterOrLogin::class, Cart::class, ]); $this->assertEquals(Purchase::defaultSteps(), $results); $results = $this->sort([ RegisterOrLogin::class, RFF::class, Methods::class, Cart::class, ]); $this->assertEquals([ Setup::class, RegisterOrLogin::class, RFF::class, Methods::class, Cart::class, Submit::class, ], $results); $results = $this->sort([ RegisterOrLogin::class, RFF::class, Cart::class, ]); $this->assertEquals([ Setup::class, RegisterOrLogin::class, RFF::class, Cart::class, Submit::class, ], $results); } private function sort(array $dependencies): array { $errors = StepService::check($dependencies); if (count($errors)) { return Purchase::defaultSteps(); } return [Setup::class, ...$dependencies, Submit::class]; // Note: Re-index if you're doing any index-based checking/comparision. } }