Inheritance: extends lithium\data\source\Result
示例#1
0
 public function testIterationWithPeek()
 {
     $records = array("one", "two", "three", "four");
     $iterator = new MockResult(compact('records'));
     $map = array("one" => "two", "two" => "three", "three" => "four", "four" => false);
     $result = array();
     foreach ($iterator as $key => $val) {
         $result[] = $val;
         $this->assertEqual($iterator->peek(), $map[$val]);
     }
     $this->assertEqual($records, $result);
 }
 public function testMockResultContent()
 {
     $result = new MockResult(array('records' => array()));
     $result->rewind();
     $i = 0;
     foreach ($result as $r) {
         $i++;
     }
     $this->assertEqual(0, $i);
     $records = array(array('id' => 1, 'data' => 'data1'), array('id' => 2, 'data' => 'data2'), array('id' => 3, 'data' => 'data3'), array('id' => 4, 'data' => 'data4'));
     $result = new MockResult(array('records' => $records));
     $i = 0;
     foreach ($result as $s) {
         $this->assertEqual($records[$i], $s);
         $i++;
     }
     $this->assertEqual(4, $i);
     $records = array(array(false), array('id' => 1, 'data' => 'data1'), array('id' => 2, 'data' => 'data2'), array('id' => 3, 'data' => 'data3'), array('id' => 4, 'data' => 'data4'));
     $result = new MockResult(array('records' => $records));
     $i = 0;
     foreach ($result as $s) {
         $this->assertEqual($records[$i], $s);
         $i++;
     }
     $this->assertEqual(5, $i);
 }