dit_006.phpt 750 B

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