Skip to content

Commit

Permalink
Simplify CacheSpy test double class (#596)
Browse files Browse the repository at this point in the history
Co-authored-by: Norbert Orzechowicz <[email protected]>
  • Loading branch information
stloyd and norberttech authored Oct 16, 2023
1 parent 5822158 commit 9dea8bb
Showing 1 changed file with 11 additions and 39 deletions.
50 changes: 11 additions & 39 deletions src/core/etl/tests/Flow/ETL/Tests/Double/CacheSpy.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,16 @@
*/
final class CacheSpy implements Cache
{
/**
* @var array<string, int>
*/
private array $clears = [];
private int $clearsCount = 0;

/**
* @var array<string, int>
*/
private array $reads = [];

/**
* @var array<string, int>
*/
private array $writes = [];
private int $readsCount = 0;

private int $writesCount = 0;

public function __construct(private readonly Cache $cache)
{
Expand All @@ -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
Expand All @@ -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;
}
}

0 comments on commit 9dea8bb

Please sign in to comment.