Basic cursor test --FILE-- <?php use php\util\Flow; echo "--test array\n"; $cursor = Flow::of([1, 2, 3]); foreach ($cursor as $el) { var_dump($el); } echo "--test range\n"; $cursor = Flow::ofRange(5, 7); foreach ($cursor as $el) { var_dump($el); } echo "--test range with step\n"; $cursor = Flow::ofRange(5, 10, 2); foreach ($cursor as $el) { var_dump($el); } echo "--test string\n"; $cursor = Flow::ofString('foo'); foreach ($cursor as $el) { var_dump($el); } echo "--test string with chunk size\n"; $cursor = Flow::ofString('foobar', 2); foreach ($cursor as $el) { var_dump($el); } ?> --EXPECT--
--TEST-- IteratorIterator with iterator --FILE-- <?php use php\util\Flow; $it = new IteratorIterator(Flow::ofRange(1, 3)); foreach ($it as $key => $el) { var_dump($el); var_dump($key); echo "\n"; } foreach ($it as $el) { echo $el; } ?> --EXPECT-- int(1) int(0) int(2) int(1) int(3) int(2)
--TEST-- Basic cursor test limit and offset + count; --FILE-- <?php use php\util\Flow; $cursor = Flow::ofRange(1, 99); var_dump('count_with_skip=' . $cursor->skip(19)->count()); $cursor = Flow::ofRange(1, 99); var_dump('count_with_limit=' . $cursor->limit(20)->count()); $cursor = Flow::ofRange(1, 99); var_dump('count_with_skip+limit=' . $cursor->skip(20)->limit(40)->count()); echo "--\n"; $cursor = Flow::of([10, 20, 30, 40, 50])->skip(1)->limit(3)->each(function ($el) { var_dump($el); }); ?> --EXPECT-- string(18) "count_with_skip=80" string(19) "count_with_limit=20" string(24) "count_with_skip+limit=40" -- int(20) int(30) int(40)