isEmpty())->toBeTrue(); expect($collection->count())->toBe(0); }); it('creates collection from array', function () { $fragments = [ 'header' => '

Title

', 'content' => '

Content

', 'footer' => '', ]; $collection = FragmentCollection::fromArray($fragments); expect($collection->isEmpty())->toBeFalse(); expect($collection->count())->toBe(3); }); it('checks if has fragment', function () { $collection = FragmentCollection::fromArray([ 'header' => '

Title

', 'content' => '

Content

', ]); expect($collection->has('header'))->toBeTrue(); expect($collection->has('content'))->toBeTrue(); expect($collection->has('footer'))->toBeFalse(); }); it('gets fragment by name', function () { $collection = FragmentCollection::fromArray([ 'header' => '

Title

', 'content' => '

Content

', ]); expect($collection->get('header'))->toBe('

Title

'); expect($collection->get('content'))->toBe('

Content

'); expect($collection->get('non-existent'))->toBeNull(); }); it('converts to associative array', function () { $original = [ 'header' => '

Title

', 'content' => '

Content

', 'footer' => '', ]; $collection = FragmentCollection::fromArray($original); $array = $collection->toAssociativeArray(); expect($array)->toBe($original); }); it('gets all fragments', function () { $fragments = [ 'header' => '

Title

', 'content' => '

Content

', ]; $collection = FragmentCollection::fromArray($fragments); expect($collection->all())->toBe($fragments); }); it('counts fragments', function () { $collection = FragmentCollection::fromArray([ 'one' => '
1
', 'two' => '
2
', 'three' => '
3
', ]); expect($collection->count())->toBe(3); }); it('checks if empty', function () { $empty = FragmentCollection::empty(); expect($empty->isEmpty())->toBeTrue(); $notEmpty = FragmentCollection::fromArray(['test' => '
Test
']); expect($notEmpty->isEmpty())->toBeFalse(); }); it('is iterable', function () { $fragments = [ 'header' => '

Title

', 'content' => '

Content

', 'footer' => '', ]; $collection = FragmentCollection::fromArray($fragments); $iterated = []; foreach ($collection as $name => $html) { $iterated[$name] = $html; } expect($iterated)->toBe($fragments); }); it('is countable', function () { $collection = FragmentCollection::fromArray([ 'one' => '
1
', 'two' => '
2
', ]); // count() should work directly on the object expect(count($collection))->toBe(2); }); it('handles empty array creation', function () { $collection = FragmentCollection::fromArray([]); expect($collection->isEmpty())->toBeTrue(); expect($collection->count())->toBe(0); expect($collection->toAssociativeArray())->toBe([]); }); it('preserves fragment order', function () { $fragments = [ 'first' => '
1
', 'second' => '
2
', 'third' => '
3
', ]; $collection = FragmentCollection::fromArray($fragments); $keys = array_keys($collection->toAssociativeArray()); expect($keys)->toBe(['first', 'second', 'third']); }); it('handles fragments with complex HTML', function () { $complexHtml = <<

Title

New

This is complex HTML with links

HTML; $collection = FragmentCollection::fromArray([ 'complex-card' => $complexHtml, ]); $retrieved = $collection->get('complex-card'); expect($retrieved)->toBe($complexHtml); expect($retrieved)->toContain('data-id="123"'); expect($retrieved)->toContain('complex'); }); it('handles fragments with special characters', function () { $specialHtml = '
Special chars: & < > "quotes" \'apostrophes\'
'; $collection = FragmentCollection::fromArray([ 'special' => $specialHtml, ]); expect($collection->get('special'))->toBe($specialHtml); }); it('returns null for non-existent fragments consistently', function () { $collection = FragmentCollection::fromArray([ 'existing' => '
Exists
', ]); expect($collection->get('non-existent'))->toBeNull(); expect($collection->get('another-missing'))->toBeNull(); expect($collection->get(''))->toBeNull(); }); });