Skip to content

Instantly share code, notes, and snippets.

@mlebkowski
Last active August 3, 2021 09:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mlebkowski/4b90b97f8788cddf7f527c34dc2f1804 to your computer and use it in GitHub Desktop.
Save mlebkowski/4b90b97f8788cddf7f527c34dc2f1804 to your computer and use it in GitHub Desktop.
public function findUpcomingForPatient(Patient $patient): ?Visit
{
- return $this->cache->fetch($patient->getId())
- ?: $this->visits->findUpcomingForPatient($patient);
+ $key = $patient->getId();
+ if ($this->cache->contains($key)) {
+ return $this->cache->fetch($key);
+ }
+
+ return $this->visits->findUpcomingForPatient($patient);
}
<?php
public function repository call is prevented if the cache contains a null value()
{
// given …
// when:
$sut->prefetch($this->task);
// then:
$visits
->expects(self::never())
->method('findUpcomingForPatient');
$sut->findUpcomingForPatient($this->patient);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment