From 33afba30cb517b02452f98c8719d77e803c963aa Mon Sep 17 00:00:00 2001 From: Jesse Gall Date: Mon, 6 Feb 2023 18:09:11 +0100 Subject: [PATCH] Added count method --- src/ContainsData.php | 10 ++++++++++ tests/ContainsDataTest.php | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/src/ContainsData.php b/src/ContainsData.php index ab709d6..310b2dc 100644 --- a/src/ContainsData.php +++ b/src/ContainsData.php @@ -277,4 +277,14 @@ public function clear(array $except = []): void $container = $persist->container(); } + + /** + * Get the count of the container + * + * @return int + */ + public function count(): int + { + return count($this->container()); + } } diff --git a/tests/ContainsDataTest.php b/tests/ContainsDataTest.php index 1a6388b..b322e24 100644 --- a/tests/ContainsDataTest.php +++ b/tests/ContainsDataTest.php @@ -422,4 +422,9 @@ public function test_when_remove_but_key_does_not_exist_then_nothing_happens() $this->assertFalse($this->subject->has('missing.property')); } + public function test_when_count_then_correct_count() + { + $this->assertEquals(3, $this->subject->count()); + } + } \ No newline at end of file