summaryrefslogtreecommitdiffstats
path: root/tests/modules/database/driver/mysql/resultTest.php
blob: 5159e394ad3d2c7de28b2ec2fe10e46e486a5337 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
require_once('/../../../../../modules/database/classes/database/result.php');
require_once('/../../../../../modules/database/classes/driver/mysql/result.php');
/**
 * Generated by PHPUnit_SkeletonGenerator 1.2.0 on 2013-02-06 at 20:48:50.
 */
class Result_Mysql_DriverTest extends PHPUnit_Framework_TestCase
{
    /**
     * @var Result_Mysql_Driver
     */
    protected $object;

    /**
     * Sets up the fixture, for example, opens a network connection.
     * This method is called before a test is executed.
     */
    protected function setUp()
    {
		$stub = $this->getMockBuilder('mysqli_result')
						->disableOriginalConstructor()
						->getMock();
		$stub->expects($this->any())
			->method('fetch_object')
			->will($this->onConsecutiveCalls(
				(object) array('id' => 1, 'name' => 'Tinkerbell'),
				(object) array('id' => 2, 'name' => 'Trixie'),
				null
			));

        $this->object = new Result_Mysql_Driver($stub);
    }

    /**
     * Tears down the fixture, for example, closes a network connection.
     * This method is called after a test is executed.
     */
    protected function tearDown()
    {
    } 

    /**
     * @covers Result_Mysql_Driver::rewind
     * @todo   Implement testRewind().
     */
    public function testRewind()
    {
        $except = false;
		$this->object->valid();
		$this->object->rewind();
		$this->object->next();
		try {
			$this->object->rewind();
		}catch(Exception $e) {
			$except=true;
		}
		$this->assertEquals(true,$except);
    }

   	
	/**
     * @covers Result_Mysql_Driver::current
     */
	public function testCurrent() {
		$this->assertEquals($this->object->current()->name,'Tinkerbell');
	}
	
	/**
     * @covers Result_Mysql_Driver::valid
     */
	public function testVaid() {
		$this->assertEquals($this->object->valid(),true);
	}
	
	/**
     * @covers Result_Mysql_Driver::key
     */
	public function testKey() {
		$this->assertEquals($this->object->key(),0);
	}
	
	/**
     * @covers Result_Mysql_Driver::key
     */
	public function testGet() {
		$this->assertEquals($this->object->get('id'),1);
	}
	
	/**
     * @covers Result_Mysql_Driver::as_array
     */
	public function testAs_Array() {
		$arr = $this->object->as_array();
		$this->assertArrayHasKey(0, $arr);
		$this->assertArrayHasKey('name', (array)$arr[0]);
		$this->assertEquals($arr[0]->name, 'Tinkerbell');
		$this->assertArrayHasKey(1, $arr);
		$this->assertArrayHasKey('id', (array)$arr[1]);
		$this->assertEquals($arr[1]->id, 2);
	}
	
	public function testIterator(){
		$this->assertEquals($this->object->valid(), true);
		$this->assertEquals($this->object->get('id'), 1);
		foreach($this->object as $key => $row) {
			if ($key == 0) {
				$this->assertEquals($row->name, 'Tinkerbell');
				$this->assertEquals($row->id, 1);
			}
			if ($key == 1) {
				$this->assertEquals($row->name, 'Trixie');
				$this->assertEquals(2, $this->object->get('id'));
				$this->assertEquals($row->id, 2);
			}
		}
		$this->assertEquals(false,$this->object->valid());
		$this->assertEquals(null, $this->object->get('id'));
		$this->assertEquals(null, $this->object->current());
		$this->object->next();
		$this->object->next();
		$this->object->next();
		$this->assertEquals(1,$this->object->key());
	
	}
}