From f8aa42c3548b4b295ff79b435b75cc90aedee9cb Mon Sep 17 00:00:00 2001 From: Marcos Felipe Date: Tue, 15 Feb 2022 14:59:53 -0300 Subject: [PATCH] fix: Implement count in Container Implement count method in Container to retrieve set values quantity Close #17 --- src/Container.php | 8 ++++++++ test/ContainerTest.php | 15 +++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/Container.php b/src/Container.php index e3c0c990..36476500 100644 --- a/src/Container.php +++ b/src/Container.php @@ -30,4 +30,12 @@ public function &offsetGet($key) return $ret; } + + public function count() + { + $storage = $this->getStorage(); + $name = $this->getName(); + + return count($storage[$name]); + } } diff --git a/test/ContainerTest.php b/test/ContainerTest.php index 56b11b7e..df0dc6a1 100644 --- a/test/ContainerTest.php +++ b/test/ContainerTest.php @@ -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); + } }