Skip to content

Commit

Permalink
fix: Implement count in Container
Browse files Browse the repository at this point in the history
Implement count method in Container to retrieve set values quantity

Close laminas#17

Signed-off-by: Marcos Felipe <[email protected]>
  • Loading branch information
omarkdev committed Feb 15, 2022
1 parent 928aea6 commit 3082491
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,17 @@ public function &offsetGet($key)

return $ret;
}

/**
* Get the number of set values in container.
*
* @return int
*/
public function count()
{
$storage = $this->getStorage();
$name = $this->getName();

return count($storage[$name]);
}
}
15 changes: 15 additions & 0 deletions test/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -560,4 +560,19 @@ public function testGetArrayCopyAfterExchangeArray(): void
self::assertIsArray($contents);
self::assertArrayHasKey('foo', $contents, "'getArrayCopy' doesn't return exchanged array");
}

/**
* Test count method is retrieving
* set values quantity.
*
* @test
*/
public function testCountIsRetrievingSetValuesQuantity(): void
{
$this->container->foo = ['bar' => 'baz'];
$this->container->bar = ['foo' => 'baz'];
$this->container->baz = ['bar' => 'foo'];

self::assertCount(3, $this->container);
}
}

0 comments on commit 3082491

Please sign in to comment.