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

Commit

Permalink
Merge branch 'feature/7263'
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Mar 25, 2015
181 parents c9d94b2 + a72a9a7 + 339cf31 + 3833182 + fd8deb8 + 4cda17f + 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 + f028776 + 60ef0d1 + 76edd11 + 32f5dbc commit c5b5652
Show file tree
Hide file tree
Showing 6 changed files with 192 additions and 115 deletions.
51 changes: 11 additions & 40 deletions src/Adapter/Null.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,51 +9,22 @@

namespace Zend\Paginator\Adapter;

class Null implements AdapterInterface
class Null extends NullFill
{
/**
* Item count
*
* @var int
*/
protected $count = null;

/**
* Constructor.
*
* @param int $count Total item count (Optional)
* {@inheritdoc}
*/
public function __construct($count = 0)
{
$this->count = $count;
}

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

$remainItemCount = $this->count() - $offset;
$currentItemCount = $remainItemCount > $itemCountPerPage ? $itemCountPerPage : $remainItemCount;

return array_fill(0, $currentItemCount, null);
}
trigger_error(
sprintf(
'The class %s has been deprecated; please use %s\\NullFill',
__CLASS__,
__NAMESPACE__
),
E_USER_DEPRECATED
);

/**
* Returns the total number of rows in the array.
*
* @return int
*/
public function count()
{
return $this->count;
parent::__construct($count);
}
}
59 changes: 59 additions & 0 deletions src/Adapter/NullFill.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\Paginator\Adapter;

class NullFill implements AdapterInterface
{
/**
* Item count
*
* @var int
*/
protected $count = null;

/**
* Constructor.
*
* @param int $count Total item count (Optional)
*/
public function __construct($count = 0)
{
$this->count = $count;
}

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

$remainItemCount = $this->count() - $offset;
$currentItemCount = $remainItemCount > $itemCountPerPage ? $itemCountPerPage : $remainItemCount;

return array_fill(0, $currentItemCount, null);
}

/**
* Returns the total number of rows in the array.
*
* @return int
*/
public function count()
{
return $this->count;
}
}
15 changes: 14 additions & 1 deletion src/AdapterPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@
*/
class AdapterPluginManager extends AbstractPluginManager
{
/**
* Default aliases
*
* Primarily for ensuring previously defined adapters select their
* current counterparts.
*
* @var array
*/
protected $aliases = array(
'null' => 'nullfill',
'Zend\Paginator\Adapter\Null' => 'nullfill',
);

/**
* Default set of adapters
*
Expand All @@ -28,7 +41,7 @@ class AdapterPluginManager extends AbstractPluginManager
protected $invokableClasses = array(
'array' => 'Zend\Paginator\Adapter\ArrayAdapter',
'iterator' => 'Zend\Paginator\Adapter\Iterator',
'null' => 'Zend\Paginator\Adapter\Null',
'nullfill' => 'Zend\Paginator\Adapter\NullFill',
);

/**
Expand Down
96 changes: 96 additions & 0 deletions test/Adapter/NullFillTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 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;
use Zend\Paginator;

/**
* @group Zend_Paginator
*/
class NullFillTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Zend\Paginator\Adapter\Array
*/
private $adapter;

/**
* Prepares the environment before running a test.
*/
protected function setUp()
{
parent::setUp();
$this->adapter = new Adapter\NullFill(101);
}
/**
* Cleans up the environment after running a test.
*/
protected function tearDown()
{
$this->adapter = null;
parent::tearDown();
}

public function testGetsItems()
{
$actual = $this->adapter->getItems(0, 10);
$this->assertEquals(array_fill(0, 10, null), $actual);
}

public function testReturnsCorrectCount()
{
$this->assertEquals(101, $this->adapter->count());
}

/**
* @group ZF-3873
*/
public function testAdapterReturnsCorrectValues()
{
$paginator = new Paginator\Paginator(new Adapter\NullFill(2));
$paginator->setCurrentPageNumber(1);
$paginator->setItemCountPerPage(5);

$pages = $paginator->getPages();

$this->assertEquals(2, $pages->currentItemCount);
$this->assertEquals(2, $pages->lastItemNumber);

$paginator = new Paginator\Paginator(new Adapter\NullFill(19));
$paginator->setCurrentPageNumber(4);
$paginator->setItemCountPerPage(5);

$pages = $paginator->getPages();

$this->assertEquals(4, $pages->currentItemCount);
$this->assertEquals(19, $pages->lastItemNumber);
}

/**
* @group ZF-4151
*/
public function testEmptySet()
{
$this->adapter = new Adapter\NullFill(0);
$actual = $this->adapter->getItems(0, 10);
$this->assertEquals(array(), $actual);
}

/**
* Verify that the fix for ZF-4151 doesn't create an OBO error
*/
public function testSetOfOne()
{
$this->adapter = new Adapter\NullFill(1);
$actual = $this->adapter->getItems(0, 10);
$this->assertEquals(array_fill(0, 1, null), $actual);
}
}
79 changes: 7 additions & 72 deletions test/Adapter/NullTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,87 +10,22 @@
namespace ZendTest\Paginator\Adapter;

use Zend\Paginator\Adapter;
use Zend\Paginator;

/**
* @group Zend_Paginator
*/
class NullTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Zend\Paginator\Adapter\Array
*/
private $adapter;

/**
* Prepares the environment before running a test.
*/
protected function setUp()
{
parent::setUp();
$this->adapter = new Adapter\Null(101);
}
/**
* Cleans up the environment after running a test.
*/
protected function tearDown()
{
$this->adapter = null;
parent::tearDown();
}

public function testGetsItems()
{
$actual = $this->adapter->getItems(0, 10);
$this->assertEquals(array_fill(0, 10, null), $actual);
}

public function testReturnsCorrectCount()
{
$this->assertEquals(101, $this->adapter->count());
}

/**
* @group ZF-3873
*/
public function testAdapterReturnsCorrectValues()
{
$paginator = new Paginator\Paginator(new Adapter\Null(2));
$paginator->setCurrentPageNumber(1);
$paginator->setItemCountPerPage(5);

$pages = $paginator->getPages();

$this->assertEquals(2, $pages->currentItemCount);
$this->assertEquals(2, $pages->lastItemNumber);

$paginator = new Paginator\Paginator(new Adapter\Null(19));
$paginator->setCurrentPageNumber(4);
$paginator->setItemCountPerPage(5);

$pages = $paginator->getPages();

$this->assertEquals(4, $pages->currentItemCount);
$this->assertEquals(19, $pages->lastItemNumber);
}

/**
* @group ZF-4151
*/
public function testEmptySet()
public function setUp()
{
$this->adapter = new Adapter\Null(0);
$actual = $this->adapter->getItems(0, 10);
$this->assertEquals(array(), $actual);
if (version_compare(PHP_VERSION, '7.0', '>=')) {
$this->markTestSkipped('Cannot test Null adapter under PHP 7; reserved keyword');
}
}

/**
* Verify that the fix for ZF-4151 doesn't create an OBO error
*/
public function testSetOfOne()
public function testRaisesNoticeOnInstantiation()
{
$this->adapter = new Adapter\Null(1);
$actual = $this->adapter->getItems(0, 10);
$this->assertEquals(array_fill(0, 1, null), $actual);
$this->setExpectedException('PHPUnit_Framework_Error_Deprecated');
new Adapter\Null();
}
}
7 changes: 5 additions & 2 deletions test/AdapterPluginManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function testCanRetrieveAdapterPlugin()
$plugin = $this->adapaterPluginManager->get('dbselect', array($this->mockSelect, $this->mockAdapter));
$this->assertInstanceOf('Zend\Paginator\Adapter\DbSelect', $plugin);
$plugin = $this->adapaterPluginManager->get('null', 101);
$this->assertInstanceOf('Zend\Paginator\Adapter\Null', $plugin);
$this->assertInstanceOf('Zend\Paginator\Adapter\NullFill', $plugin);

//test dbtablegateway
$mockStatement = $this->getMock('Zend\Db\Adapter\Driver\StatementInterface');
Expand All @@ -79,7 +79,10 @@ public function testCanRetrieveAdapterPlugin()
$order = "foo";
$group = "foo";
$having = "count(foo)>0";
$plugin = $this->adapaterPluginManager->get('dbtablegateway', array($mockTableGateway, $where, $order, $group, $having));
$plugin = $this->adapaterPluginManager->get(
'dbtablegateway',
array($mockTableGateway, $where, $order, $group, $having)
);
$this->assertInstanceOf('Zend\Paginator\Adapter\DbTableGateway', $plugin);

//test callback
Expand Down

0 comments on commit c5b5652

Please sign in to comment.