public function testTwoFullIterationsWithInterupt()
 {
     $dao = new Dao();
     $itr = new RewindableEntityIterator($dao->queryWidgets(), new WidgetDataMapper());
     $results = array();
     $i = 0;
     foreach ($itr as $widget) {
         if (++$i > 1) {
             break;
         }
         $results[] = $widget;
     }
     $this->assertTrue(count($results) == 1);
     $results = array();
     /* Prints this time */
     foreach ($itr as $widget) {
         $results[] = $widget;
     }
     $this->assertTrue(count($results) == 3);
 }
Exemplo n.º 2
0
<?php

namespace org\mizer;

require __DIR__ . '/src/ClassLoader.class.php';
spl_autoload_register(array(new ClassLoader(), 'load'));
/* Instantiate data ccess object */
$dao = new Dao();
/* Compose iterator from DAO ResultSet and Widget DataMapper */
$itr = new RewindableEntityIterator($dao->queryWidgets(), new WidgetDataMapper());
/* Prints this time */
foreach ($itr as $widget) {
    print_r($widget);
}
/* Doesn't print this time */
foreach ($itr as $widget) {
    print_r($widget);
}