This repository has been archived by the owner on Jan 8, 2020. It is now read-only.
/
RowGatewayTest.php
105 lines (91 loc) · 3.74 KB
/
RowGatewayTest.php
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
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Db
*/
namespace ZendTest\Db\RowGateway;
use Zend\Db\RowGateway\RowGateway;
/**
* Generated by PHPUnit_SkeletonGenerator on 2012-03-01 at 21:02:22.
*/
class RowGatewayTest extends \PHPUnit_Framework_TestCase
{
protected $mockAdapter = null;
public function setup()
{
// mock the adapter, driver, and parts
$mockResult = $this->getMock('Zend\Db\Adapter\Driver\ResultInterface');
$mockStatement = $this->getMock('Zend\Db\Adapter\Driver\StatementInterface');
$mockStatement->expects($this->any())->method('execute')->will($this->returnValue($mockResult));
$mockConnection = $this->getMock('Zend\Db\Adapter\Driver\ConnectionInterface');
$mockDriver = $this->getMock('Zend\Db\Adapter\Driver\DriverInterface');
$mockDriver->expects($this->any())->method('createStatement')->will($this->returnValue($mockStatement));
$mockDriver->expects($this->any())->method('getConnection')->will($this->returnValue($mockConnection));
// setup mock adapter
$this->mockAdapter = $this->getMock('Zend\Db\Adapter\Adapter', null, array($mockDriver));
}
public function testOffsetSet()
{
// If we set with an index, both getters should retrieve the same value:
$row = new RowGateway('id', 'fake', $this->mockAdapter);
$row['testColumn'] = 'test';
$this->assertEquals('test', $row->testColumn);
$this->assertEquals('test', $row['testColumn']);
}
public function test__set()
{
// If we set with a property, both getters should retrieve the same value:
$row = new RowGateway('id', 'fake', $this->mockAdapter);
$row->testColumn = 'test';
$this->assertEquals('test', $row->testColumn);
$this->assertEquals('test', $row['testColumn']);
}
public function test__isset()
{
// Test isset before and after assigning to a property:
$row = new RowGateway('id', 'fake', $this->mockAdapter);
$this->assertFalse(isset($row->foo));
$row->foo = 'bar';
$this->assertTrue(isset($row->foo));
// Test isset before and after assigning to an index:
$row = new RowGateway('id', 'fake', $this->mockAdapter);
$this->assertFalse(isset($row->foo));
$row['foo'] = 'bar';
$this->assertTrue(isset($row->foo));
}
public function testOffsetExists()
{
// Test isset before and after assigning to a property:
$row = new RowGateway('id', 'fake', $this->mockAdapter);
$this->assertFalse(isset($row['foo']));
$row->foo = 'bar';
$this->assertTrue(isset($row['foo']));
// Test isset before and after assigning to an index:
$row = new RowGateway('id', 'fake', $this->mockAdapter);
$this->assertFalse(isset($row['foo']));
$row['foo'] = 'bar';
$this->assertTrue(isset($row['foo']));
}
public function test__unset()
{
$row = new RowGateway('id', 'fake', $this->mockAdapter);
$row->foo = 'bar';
$this->assertEquals('bar', $row->foo);
unset($row->foo);
$this->assertEmpty($row->foo);
$this->assertEmpty($row['foo']);
}
public function testOffsetUnset()
{
$row = new RowGateway('id', 'fake', $this->mockAdapter);
$row['foo'] = 'bar';
$this->assertEquals('bar', $row['foo']);
unset($row['foo']);
$this->assertEmpty($row->foo);
$this->assertEmpty($row['foo']);
}
}