From 1b563ef6b12045a34018d6dbf2a0a7a8b97cd84c Mon Sep 17 00:00:00 2001 From: Dirk Wenzel Date: Wed, 2 Sep 2015 18:02:03 +0200 Subject: [PATCH] [BUGFIX] AbstractDemand-> setLimit doesn't allow zero value anymore. fixes #30 --- Classes/Domain/Model/Dto/AbstractDemand.php | 16 ++++++++++------ Tests/Unit/Domain/Model/AbstractDemandTest.php | 12 ++++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/Classes/Domain/Model/Dto/AbstractDemand.php b/Classes/Domain/Model/Dto/AbstractDemand.php index 58a7fc99..cd09f415 100644 --- a/Classes/Domain/Model/Dto/AbstractDemand.php +++ b/Classes/Domain/Model/Dto/AbstractDemand.php @@ -111,12 +111,16 @@ class AbstractDemand extends AbstractEntity implements DemandInterface { protected $search; /** - * @param int $limit A limit for the demand - * @return void - */ - public function setLimit ($limit = 100) { - $this->limit = (int)$limit; - } + * Sets the limit + * + * @param int $limit A limit for the demand. Only values > 0 are allowed. Default 100 + * @return void + */ + public function setLimit($limit = 100) { + if ($validatedLimit = (int) $limit > 0) { + $this->limit = (int) $limit; + } + } /** * @return \string The time limit for the demand diff --git a/Tests/Unit/Domain/Model/AbstractDemandTest.php b/Tests/Unit/Domain/Model/AbstractDemandTest.php index 7e1e14b7..2817522f 100644 --- a/Tests/Unit/Domain/Model/AbstractDemandTest.php +++ b/Tests/Unit/Domain/Model/AbstractDemandTest.php @@ -108,6 +108,18 @@ public function setLimitCastsStringToInteger () { ); } + /** + * @test + * @covers ::setLimit + */ + public function setLimitValidatesLimitGreatherThanZero() { + $this->fixture->setLimit(-1); + $this->assertSame( + 100, + $this->fixture->getLimit() + ); + } + /** * @test * @covers ::getOffset