});
describe('.times', function () {
it('should be fluid', function () {
assert_is_a((new FluidXml())->times(4), FluidRepeater::class);
assert_is_fluid('times', 4, function () {
});
});
it('should repeat the following one method call (if no callable is passed)', function () {
$xml = new FluidXml();
$xml->times(2)->add('child')->add('lastchild');
$expected = "<doc>\n" . " <child/>\n" . " <child/>\n" . " <lastchild/>\n" . "</doc>";
assert_equal_xml($xml, $expected);
});
it('should switch context', function () {
$xml = new FluidXml();
$xml->times(2)->add('child', true)->add('subchild');
$expected = "<doc>\n" . " <child>\n" . " <subchild/>\n" . " </child>\n" . " <child>\n" . " <subchild/>\n" . " </child>\n" . "</doc>";
assert_equal_xml($xml, $expected);
});
it('should repeat a closure bound to $this of the context', function () {
$xml = new FluidXml();
$xml->add('parent', true)->times(2, function ($i) {
$this->add("child{$i}");
});
$expected = "<doc>\n" . " <parent>\n" . " <child0/>\n" . " <child1/>\n" . " </parent>\n" . "</doc>";
assert_equal_xml($xml, $expected);
});
it('should repeat a callable', function () {
$xml = new FluidXml();
function addchild($parent, $i)
{