Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
Promote develop to master, becoming the next stable release.
  • Loading branch information
weierophinney committed Mar 12, 2014
184 parents b678d4c + e07a576 + ace2d81 + 77f83ca + 130a50a + f12feba + 4452247 + 2630a49 + 43cba4d + e4204b5 + d05ccf2 + e604cfb + ca97c01 + 287eb63 + 51a49db + a59e5dc + 548a07d + 8505b4c + 2716d1a + 37045c3 + 6903d5f + cdad453 + 9db7df2 + 9bb9d9a + 41b2dc0 + 5295cf8 + 27f9b6d + b273434 + 5b111b1 + ee4a022 + 5130ae3 + aff706f + f73a53d + d4a913a + b29f072 + 651a727 + 430d154 + 1839a34 + 0d5d64e + 5cde84e + dc8ee4d + 85d900a + 887c312 + 9c949ae + 0fc5669 + e29d393 + e25c698 + ca5bdbb + 18e54b8 + 73cc878 + a514416 + 778823f + fff1957 + 35beb1b + ecb2a1a + 67a31fa + c0ee14a + 7273469 + 62e104e + 293b0d0 + c59092f + b3e8431 + 615f1cb + 198a3b9 + 1630584 + 7627438 + 84a5bf6 + ad86c9d + a84a8ca + 4198a62 + e822871 + 431867b + 200dbe0 + 7277f0b + 2408da8 + 2413f67 + 4731ffc + d177c96 + b27c24b + ec13154 + 8e7b30c + 6c4437a + 2a2ed86 + 366d656 + 5f3d390 + 666d47b + dd0e03b + 1a5602a + c01cd9c + 6849552 + 8b79ca2 + e84f0d1 + 9f1b34e + c453b3e + 3d74be7 + 999502e + a46d96f + fba87c0 + ce665da + ef2dd94 + a66c89a + b997097 + da0e97d + 1302f0b + a1bbaa9 + 6bfa503 + b4b9ece + 9b1ac2d + 30880b8 + e308f6d + 8da89be + 199755f + 2310cd0 + 4e7316f + 1d6c476 + c2593db + c6ff37b + 5344902 + a35c230 + 39052a9 + 8152f2f + e0f8777 + d1f068b + 006fb88 + 6261074 + 8bf6181 + 33e79d4 + a778f16 + 57199ed + 3653e0c + 5b5a61e + 082fd49 + d56f4bf + d4ad9b4 + c2442b4 + a56d05b + 7400cfb + 8794fff + 0877be7 + 9c75f77 + 261c157 + 94f1dd4 + ae538e5 + bf68265 + c222657 + 56e71f6 + b95fff7 + 7736317 + 8a3b848 + e18ea15 + ae1a095 + a18a97f + c3ef55c + 09f0424 + 6369f0d + bbce3db + e7612d4 + af38e3f + cd3f4d4 + 498edd0 + a792bd9 + 9922da0 + 350dc8b + d9ed179 + 622be5c + 7960d27 + a406fa3 + b68216d + 0ff2c31 + 9b14073 + 3983ab0 + a7450a0 + e115947 + 66d9209 + 34a8263 + 6e4966f + ae72704 + 456507c + 3622a7c + fc740cb + 7128d47 + 4346e6d + cab6d92 + 647e52e commit 60ef0d1
Show file tree
Hide file tree
Showing 20 changed files with 239 additions and 31 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}
},
"require": {
"php": ">=5.3.3",
"php": ">=5.3.23",
"zendframework/zend-stdlib": "self.version"
},
"require-dev": {
Expand All @@ -28,7 +28,7 @@
"phpunit/PHPUnit": "~4.0"
},
"suggest": {
"zendframework/zend-cache": "To support cache feature",
"zendframework/zend-cache": "Zend\\Cache component to support cache features",
"zendframework/zend-db": "Zend\\Db component",
"zendframework/zend-filter": "Zend\\Filter component",
"zendframework/zend-json": "Zend\\Json component",
Expand Down
2 changes: 1 addition & 1 deletion src/Adapter/AdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
interface AdapterInterface extends Countable
{
/**
* Returns an collection of items for a page.
* Returns a collection of items for a page.
*
* @param int $offset Page offset
* @param int $itemCountPerPage Number of items per page
Expand Down
75 changes: 75 additions & 0 deletions src/Adapter/Callback.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\Paginator\Adapter;

use Zend\Stdlib\CallbackHandler;

class Callback implements AdapterInterface
{
/**
* Callback to be executed to retrieve the items for a page.
*
* @var CallbackHandler
*/
protected $itemsCallback;

/**
* Callback to be executed to retrieve the total number of items.
*
* @var CallbackHandler
*/
protected $countCallback;

/**
* Constructs instance.
*
* @param CallbackHandler|callable $itemsCallback Callback to be executed to retrieve the items for a page.
* @param CallbackHandler|callable $countCallback Callback to be executed to retrieve the total number of items.
*/
public function __construct($itemsCallback, $countCallback)
{
if (! $itemsCallback instanceof CallbackHandler) {
$itemsCallback = new CallbackHandler($itemsCallback);
}

if (! $countCallback instanceof CallbackHandler) {
$countCallback = new CallbackHandler($countCallback);
}

$this->itemsCallback = $itemsCallback;
$this->countCallback = $countCallback;
}

/**
* Returns an array of items for a page.
*
* Executes the {$itemsCallback}.
*
* @param int $offset Page offset
* @param int $itemCountPerPage Number of items per page
* @return array
*/
public function getItems($offset, $itemCountPerPage)
{
return $this->itemsCallback->call(array($offset, $itemCountPerPage));
}

/**
* Returns the total number of items.
*
* Executes the {$countCallback}.
*
* @return int
*/
public function count()
{
return $this->countCallback->call();
}
}
24 changes: 16 additions & 8 deletions src/Adapter/DbTableGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,38 @@
namespace Zend\Paginator\Adapter;

use Zend\Db\Sql\Where;
use Zend\Db\Sql\Having;
use Zend\Db\TableGateway\TableGateway;

class DbTableGateway extends DbSelect
{
/**
* Constructs instance.
*
* @param TableGateway $tableGateway
* @param Where|\Closure|string|array $where
* @param null $order
* @param TableGateway $tableGateway
* @param null|Where|\Closure|string|array $where
* @param null|string|array $order
* @param null|string|array $group
* @param null|Having|\Closure|string|array $having
*/
public function __construct(TableGateway $tableGateway, $where = null, $order = null)
public function __construct(TableGateway $tableGateway, $where = null, $order = null, $group = null, $having = null)
{
$select = $tableGateway->getSql()->select();
$sql = $tableGateway->getSql();
$select = $sql->select();
if ($where) {
$select->where($where);
}
if ($order) {
$select->order($order);
}
if ($group) {
$select->group($group);
}
if ($having) {
$select->having($having);
}

$dbAdapter = $tableGateway->getAdapter();
$resultSetPrototype = $tableGateway->getResultSetPrototype();

parent::__construct($select, $dbAdapter, $resultSetPrototype);
parent::__construct($select, $sql, $resultSetPrototype);
}
}
2 changes: 1 addition & 1 deletion test/Adapter/ArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

Expand Down
81 changes: 81 additions & 0 deletions test/Adapter/CallbackTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\Paginator\Adapter;

use Zend\Paginator\Adapter\Callback;
use Zend\Stdlib\CallbackHandler;

/**
* @group Zend_Paginator
*/
class CallbackTest extends \PHPUnit_Framework_TestCase
{
public function testMustDefineTwoCallbacksOnContructor()
{
$itemsCallback = new CallbackHandler(function () {
return array();
});
$countCallback = new CallbackHandler(function () {
return 0;
});
$adapter = new Callback($itemsCallback, $countCallback);

$this->assertAttributeSame($itemsCallback, 'itemsCallback', $adapter);
$this->assertAttributeSame($countCallback, 'countCallback', $adapter);
}

public function testShouldAcceptAnyCallableOnContructor()
{
$itemsCallback = function () {
return range(1, 10);
};
$countCallback = 'rand';
$adapter = new Callback($itemsCallback, $countCallback);

$this->assertAttributeInstanceOf('Zend\Stdlib\CallbackHandler', 'itemsCallback', $adapter);
$this->assertAttributeInstanceOf('Zend\Stdlib\CallbackHandler', 'countCallback', $adapter);
}

public function testMustRunItemCallbackToGetItems()
{
$data = range(1, 10);
$itemsCallback = function () use ($data) {
return $data;
};
$countCallback = function () {};
$adapter = new Callback($itemsCallback, $countCallback);

$this->assertSame($data, $adapter->getItems(0, 10));
}

public function testMustPassArgumentsToGetItemCallback()
{
$data = array(0, 1, 2, 3);
$itemsCallback = function ($offset, $itemCountPerPage) {
return range($offset, $itemCountPerPage);
};
$countCallback = function () {};
$adapter = new Callback($itemsCallback, $countCallback);

$this->assertSame($data, $adapter->getItems(0, 3));
}

public function testMustRunCountCallbackToCount()
{
$count = 1988;
$itemsCallback = function () {};
$countCallback = function () use ($count) {
return $count;
};
$adapter = new Callback($itemsCallback, $countCallback);

$this->assertSame($count, $adapter->count());
}
}
2 changes: 1 addition & 1 deletion test/Adapter/DbSelectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

Expand Down
56 changes: 50 additions & 6 deletions test/Adapter/DbTableGatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\Paginator\Adapter;

use Zend\Db\Adapter\Platform\Sql92;
use Zend\Paginator\Adapter\DbTableGateway;
use Zend\Db\ResultSet\ResultSet;

Expand All @@ -23,6 +24,7 @@ class DbTableGatewayTest extends \PHPUnit_Framework_TestCase
/** @var DbTableGateway */
protected $dbTableGateway;

/** @var \Zend\Db\TableGateway\TableGateway */
protected $mockTableGateway;

public function setup()
Expand All @@ -32,13 +34,12 @@ public function setup()
$mockDriver->expects($this->any())
->method('createStatement')
->will($this->returnValue($mockStatement));
$mockPlatform = $this->getMock('Zend\Db\Adapter\Platform\PlatformInterface');
$mockPlatform->expects($this->any())
->method('getName')
->will($this->returnValue('platform'));
$mockDriver->expects($this->any())
->method('formatParameterName')
->will($this->returnArgument(0));
$mockAdapter = $this->getMockForAbstractClass(
'Zend\Db\Adapter\Adapter',
array($mockDriver, $mockPlatform)
array($mockDriver, new Sql92())
);

$tableName = 'foobar';
Expand Down Expand Up @@ -98,4 +99,47 @@ public function testGetItemsWithWhereAndOrder()
$items = $this->dbTableGateway->getItems(2, 10);
$this->assertInstanceOf('Zend\Db\ResultSet\ResultSet', $items);
}

public function testGetItemsWithWhereAndOrderAndGroup()
{
$where = "foo = bar";
$order = "foo";
$group = "foo";
$this->dbTableGateway = new DbTableGateway($this->mockTableGateway, $where, $order, $group);

$mockResult = $this->getMock('Zend\Db\Adapter\Driver\ResultInterface');
$this->mockStatement
->expects($this->once())
->method('setSql')
->with($this->equalTo('SELECT "foobar".* FROM "foobar" WHERE foo = bar GROUP BY "foo" ORDER BY "foo" ASC LIMIT limit OFFSET offset'));
$this->mockStatement
->expects($this->any())
->method('execute')
->will($this->returnValue($mockResult));

$items = $this->dbTableGateway->getItems(2, 10);
$this->assertInstanceOf('Zend\Db\ResultSet\ResultSet', $items);
}

public function testGetItemsWithWhereAndOrderAndGroupAndHaving()
{
$where = "foo = bar";
$order = "foo";
$group = "foo";
$having = "count(foo)>0";
$this->dbTableGateway = new DbTableGateway($this->mockTableGateway, $where, $order, $group, $having);

$mockResult = $this->getMock('Zend\Db\Adapter\Driver\ResultInterface');
$this->mockStatement
->expects($this->once())
->method('setSql')
->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'));
$this->mockStatement
->expects($this->any())
->method('execute')
->will($this->returnValue($mockResult));

$items = $this->dbTableGateway->getItems(2, 10);
$this->assertInstanceOf('Zend\Db\ResultSet\ResultSet', $items);
}
}
2 changes: 1 addition & 1 deletion test/Adapter/IteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

Expand Down
2 changes: 1 addition & 1 deletion test/Adapter/NullTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

Expand Down
2 changes: 1 addition & 1 deletion test/AdapterPluginManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

Expand Down
2 changes: 1 addition & 1 deletion test/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

Expand Down
2 changes: 1 addition & 1 deletion test/PaginatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

Expand Down
2 changes: 1 addition & 1 deletion test/ScrollingStyle/AllTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

Expand Down
Loading

0 comments on commit 60ef0d1

Please sign in to comment.