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
  • Loading branch information
omarkdev committed Feb 15, 2022
1 parent 928aea6 commit f8aa42c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,12 @@ public function &offsetGet($key)

return $ret;
}

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 f8aa42c

Please sign in to comment.