1: <?php
2: class IteratorTest extends AMysql_TestCase {
3:
4: public function testIterate() {
5: $data = array (
6: 'string' => array (
7: 3, 'blah'
8: )
9: );
10: $this->_amysql->insert($this->tableName, $data);
11: $stmt = $this->_amysql->query("SELECT * FROM $this->tableName");
12: $i = 0;
13: foreach ($stmt as $key => $value) {
14: if ($i == 0) {
15: $this->assertEquals(0, $key);
16: $this->assertEquals('3', $value['string']);
17: }
18: if ($i == 1) {
19: $this->assertEquals(1, $key);
20: $this->assertEquals('blah', $value['string']);
21: }
22: if ($i == 2) {
23: $this->fail();
24: }
25: $i++;
26: }
27: $i = 0;
28: foreach ($stmt as $key => $value) {
29: if ($i == 0) {
30: $this->assertEquals(0, $key);
31: $this->assertEquals('3', $value['string']);
32: }
33: if ($i == 1) {
34: $this->assertEquals(1, $key);
35: $this->assertEquals('blah', $value['string']);
36: }
37: if ($i == 2) {
38: $this->fail();
39: }
40: $i++;
41: }
42: }
43:
44: public function testIterateNonSelect() {
45: $data = array (
46: 'string' => array (
47: 3, 'blah'
48: )
49: );
50: $this->_amysql->insert($this->tableName, $data);
51: $stmt = $this->_amysql->lastStatement;
52: $this->setExpectedException('LogicException');
53: foreach ($stmt as $key => $value) {
54: }
55: }
56: }
57: ?>
58:
59: