nur-sery/nur_tests/mapper/base/ProducerTest.php

32 lines
691 B
PHP
Raw Normal View History

2024-04-04 16:26:22 +04:00
<?php
namespace nur\mapper\base;
use nur\b\io\StringReader;
use nur\mapper\line\LineReader;
use nur\t\TestCase;
class ProducerTest extends TestCase {
function testProducer() {
$p = new LineReader(new StringReader("first\nsecond\nthird\nfourth\nfifth"));
$i = 0;
$lines = [];
foreach ($p as $line) {
if ($i++ < 2) {
$lines[] = $line;
} else {
break;
}
}
$p->close();
self::assertSame(["first", "second"], $lines);
$p = new LineReader(new StringReader("first\nsecond\n"));
$lines = [];
foreach ($p as $line) {
$lines[] = $line;
}
$p->close();
self::assertSame(["first", "second"], $lines);
}
}