10
10
11
11
namespace ZendTest \Paginator \Adapter ;
12
12
13
+ use Zend \Db \Adapter \Platform \Sql92 ;
13
14
use Zend \Paginator \Adapter \DbTableGateway ;
14
15
use Zend \Paginator \Adapter \DbSelect ;
15
16
use Zend \Db \ResultSet \ResultSet ;
@@ -25,6 +26,7 @@ class DbTableGatewayTest extends \PHPUnit_Framework_TestCase
25
26
/** @var DbTableGateway */
26
27
protected $ dbTableGateway ;
27
28
29
+ /** @var \Zend\Db\TableGateway\TableGateway */
28
30
protected $ mockTableGateway ;
29
31
30
32
public function setup ()
@@ -34,13 +36,12 @@ public function setup()
34
36
$ mockDriver ->expects ($ this ->any ())
35
37
->method ('createStatement ' )
36
38
->will ($ this ->returnValue ($ mockStatement ));
37
- $ mockPlatform = $ this ->getMock ('Zend\Db\Adapter\Platform\PlatformInterface ' );
38
- $ mockPlatform ->expects ($ this ->any ())
39
- ->method ('getName ' )
40
- ->will ($ this ->returnValue ('platform ' ));
39
+ $ mockDriver ->expects ($ this ->any ())
40
+ ->method ('formatParameterName ' )
41
+ ->will ($ this ->returnArgument (0 ));
41
42
$ mockAdapter = $ this ->getMockForAbstractClass (
42
43
'Zend\Db\Adapter\Adapter ' ,
43
- array ($ mockDriver , $ mockPlatform )
44
+ array ($ mockDriver , new Sql92 () )
44
45
);
45
46
46
47
$ tableName = 'foobar ' ;
@@ -109,6 +110,10 @@ public function testGetItemsWithWhereAndOrderAndGroup()
109
110
$ this ->dbTableGateway = new DbTableGateway ($ this ->mockTableGateway , $ where , $ order , $ group );
110
111
111
112
$ mockResult = $ this ->getMock ('Zend\Db\Adapter\Driver\ResultInterface ' );
113
+ $ this ->mockStatement
114
+ ->expects ($ this ->once ())
115
+ ->method ('setSql ' )
116
+ ->with ($ this ->equalTo ('SELECT "foobar".* FROM "foobar" WHERE foo = bar GROUP BY "foo" ORDER BY "foo" ASC LIMIT limit OFFSET offset ' ));
112
117
$ this ->mockStatement
113
118
->expects ($ this ->any ())
114
119
->method ('execute ' )
@@ -128,9 +133,13 @@ public function testGetItemsWithWhereAndOrderAndGroupAndHaving()
128
133
129
134
$ mockResult = $ this ->getMock ('Zend\Db\Adapter\Driver\ResultInterface ' );
130
135
$ this ->mockStatement
131
- ->expects ($ this ->any ())
132
- ->method ('execute ' )
133
- ->will ($ this ->returnValue ($ mockResult ));
136
+ ->expects ($ this ->once ())
137
+ ->method ('setSql ' )
138
+ ->with ($ this ->equalTo ('SELECT "foobar".* FROM "foobar" WHERE foo = bar GROUP BY "foo" HAVING count(foo)>0 ORDER BY "foo" ASC LIMIT limit OFFSET offset ' ));
139
+ $ this ->mockStatement
140
+ ->expects ($ this ->any ())
141
+ ->method ('execute ' )
142
+ ->will ($ this ->returnValue ($ mockResult ));
134
143
135
144
$ items = $ this ->dbTableGateway ->getItems (2 , 10 );
136
145
$ this ->assertInstanceOf ('Zend\Db\ResultSet\ResultSet ' , $ items );
0 commit comments