Skip to content

Commit

Permalink
Fix countability bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
demiankatz committed Jun 8, 2018
1 parent d9b9846 commit 1d72517
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
12 changes: 11 additions & 1 deletion module/VuFindSearch/src/VuFindSearch/ParamBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org
*/
class ParamBag
class ParamBag implements \Countable
{
/**
* Parameters
Expand Down Expand Up @@ -238,4 +238,14 @@ function ($value) use ($name) {
}
return $request;
}

/**
* Get a count of parameters set in the bag.
*
* @return int
*/
public function count()
{
return count($this->params);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,19 @@ public function testMergeWithAll()
$bag3->mergeWithAll([$bag1, $bag2]);
$this->assertEquals(['a' => [1], 'b' => [2], 'c' => [3]], $bag3->getArrayCopy());
}

/**
* Test countability.
*
* @return void
*/
public function testCountability()
{
$bag = new ParamBag();
$this->assertEquals(0, count($bag));
$bag->set('foo', 'bar');
$this->assertEquals(1, count($bag));
$bag->set('xyzzy', 'baz');
$this->assertEquals(2, count($bag));
}
}

0 comments on commit 1d72517

Please sign in to comment.