isEmpty())->toBeTrue(); expect($errors->hasErrors())->toBeFalse(); expect($errors->count())->toBe(0); }); it('creates collection from array', function () { $errors = ErrorCollection::fromArray(['Error 1', 'Error 2']); expect($errors->isEmpty())->toBeFalse(); expect($errors->hasErrors())->toBeTrue(); expect($errors->count())->toBe(2); }); it('creates single error collection', function () { $errors = ErrorCollection::single('Test error'); expect($errors->count())->toBe(1); expect($errors->first())->toBe('Test error'); }); it('adds error immutably', function () { $errors = ErrorCollection::empty(); $updated = $errors->add('New error'); expect($errors->count())->toBe(0); expect($updated->count())->toBe(1); expect($updated->first())->toBe('New error'); }); it('adds multiple errors', function () { $errors = ErrorCollection::single('Error 1'); $updated = $errors->addMultiple(['Error 2', 'Error 3']); expect($updated->count())->toBe(3); expect($updated->toArray())->toBe(['Error 1', 'Error 2', 'Error 3']); }); it('converts to string', function () { $errors = ErrorCollection::fromArray(['Error 1', 'Error 2', 'Error 3']); expect($errors->toString())->toBe('Error 1, Error 2, Error 3'); expect($errors->toString(' | '))->toBe('Error 1 | Error 2 | Error 3'); }); it('returns first error', function () { $errors = ErrorCollection::fromArray(['First', 'Second']); expect($errors->first())->toBe('First'); }); it('returns null for empty collection first', function () { $errors = ErrorCollection::empty(); expect($errors->first())->toBeNull(); }); });