xref: /PHP-7.4/ext/spl/tests/dit_006.phpt (revision 368d3ff0)
1--TEST--
2SPL: DirectoryIterator and seek
3--FILE--
4<?php
5$di = new DirectoryIterator(__DIR__."/..");
6$di->seek(2);
7
8$n = 0;
9while ($di->valid()) {
10    $n++;
11    $di->next();
12}
13
14echo "With seek(2) we get $n\n";
15$di->seek(0);
16
17$m = 0;
18while ($di->valid()) {
19    $m++;
20    $di->next();
21}
22echo "With seek(0) we get $m\n";
23
24$o = 0;
25$di->rewind();
26while ($di->valid()) {
27    $o++;
28    $di->next();
29}
30
31echo "Without seek we get $o\n";
32
33try {
34    $p = 0;
35    $di->seek($o+1);
36    $p = 1;
37} catch (\OutOfBoundsException $ex) {
38    echo $ex->getMessage() . PHP_EOL;
39}
40
41var_dump($n !== $m, $m === $o, $p === 0);
42?>
43===DONE===
44--EXPECTF--
45With seek(2) we get %d
46With seek(0) we get %d
47Without seek we get %d
48Seek position %d is out of range
49bool(true)
50bool(true)
51bool(true)
52===DONE===
53