From 9dea8bbb739760de53f9c683c4b08afe971d693d Mon Sep 17 00:00:00 2001 From: Joseph Bielawski Date: Mon, 16 Oct 2023 15:45:47 +0200 Subject: [PATCH] Simplify `CacheSpy` test double class (#596) Co-authored-by: Norbert Orzechowicz <1921950+norberttech@users.noreply.github.com> --- .../tests/Flow/ETL/Tests/Double/CacheSpy.php | 50 ++++--------------- 1 file changed, 11 insertions(+), 39 deletions(-) diff --git a/src/core/etl/tests/Flow/ETL/Tests/Double/CacheSpy.php b/src/core/etl/tests/Flow/ETL/Tests/Double/CacheSpy.php index 96d1e7f6a..28e890ed8 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Double/CacheSpy.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Double/CacheSpy.php @@ -12,20 +12,16 @@ */ final class CacheSpy implements Cache { - /** - * @var array - */ - private array $clears = []; + private int $clearsCount = 0; /** * @var array */ private array $reads = []; - /** - * @var array - */ - private array $writes = []; + private int $readsCount = 0; + + private int $writesCount = 0; public function __construct(private readonly Cache $cache) { @@ -42,35 +38,21 @@ public function __unserialize(array $data) : void public function add(string $id, Rows $rows) : void { - if (!\array_key_exists($id, $this->writes)) { - $this->writes[$id] = 1; - } else { - $this->writes[$id] += 1; - } + $this->writesCount++; $this->cache->add($id, $rows); } public function clear(string $id) : void { - if (!\array_key_exists($id, $this->clears)) { - $this->clears[$id] = 1; - } else { - $this->clears[$id] += 1; - } + $this->clearsCount++; $this->cache->clear($id); } public function clears() : int { - $total = 0; - - foreach ($this->clears as $clears) { - $total += $clears; - } - - return $total; + return $this->clearsCount; } public function has(string $id) : bool @@ -90,28 +72,18 @@ public function read(string $id) : \Generator $this->reads[$id] += 1; } + $this->readsCount++; + return $this->cache->read($id); } public function reads() : int { - $total = 0; - - foreach ($this->reads as $reads) { - $total += $reads; - } - - return $total; + return $this->readsCount; } public function writes() : int { - $total = 0; - - foreach ($this->writes as $writes) { - $total += $writes; - } - - return $total; + return $this->writesCount; } }