CountableIteratorReaderTest.php 966 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace Ddeboer\DataImport\Tests\Reader;
  3. use Ddeboer\DataImport\Reader\CountableIteratorReader;
  4. /**
  5. * @author Márk Sági-Kazár <mark.sagikazar@gmail.com>
  6. */
  7. class CountableIteratorReaderTest extends \PHPUnit_Framework_TestCase
  8. {
  9. public function testCount()
  10. {
  11. $iterator = new \ArrayIterator([
  12. [
  13. 'id' => 1,
  14. 'username' => 'john.doe',
  15. 'name' => 'John Doe',
  16. ],
  17. ]);
  18. $reader = new CountableIteratorReader($iterator);
  19. // We need to rewind the iterator
  20. $reader->rewind();
  21. $this->assertEquals(1, $reader->count());
  22. }
  23. public function testIteratorCount()
  24. {
  25. $reader = new CountableIteratorReader(new CountableIterator);
  26. // We need to rewind the iterator
  27. $reader->rewind();
  28. $this->assertEquals(0, $reader->count());
  29. }
  30. }
  31. class CountableIterator extends \EmptyIterator
  32. {
  33. }