isEmpty())->toBeTrue(); expect($collection->count())->toBe(0); }); it('creates collection from array', function () { $fragments = [ 'header' => '
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' => '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' => 'Content
', ]); expect($collection->get('header'))->toBe('Content
'); expect($collection->get('non-existent'))->toBeNull(); }); it('converts to associative array', function () { $original = [ 'header' => 'Content
', 'footer' => '', ]; $collection = FragmentCollection::fromArray($original); $array = $collection->toAssociativeArray(); expect($array)->toBe($original); }); it('gets all fragments', function () { $fragments = [ 'header' => 'Content
', ]; $collection = FragmentCollection::fromArray($fragments); expect($collection->all())->toBe($fragments); }); it('counts fragments', function () { $collection = FragmentCollection::fromArray([ 'one' => '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' => 'This is complex HTML with links