-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #111 from wandersonwhcr/feature/cache
Cache
- Loading branch information
Showing
9 changed files
with
320 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Romans\Cache; | ||
|
||
use Psr\Cache\CacheItemPoolInterface as CacheInterface; | ||
|
||
/** | ||
* Cache Aware Trait | ||
*/ | ||
trait CacheAwareTrait | ||
{ | ||
private ?CacheInterface $cache = null; | ||
|
||
/** | ||
* Has Cache? | ||
* | ||
* @return bool Cache Exists | ||
*/ | ||
public function hasCache(): bool | ||
{ | ||
return $this->cache !== null; | ||
} | ||
|
||
/** | ||
* Set Cache | ||
* | ||
* @param ?CacheInterface $cache Cache Object | ||
* @param self Fluent Interface | ||
*/ | ||
public function setCache(?CacheInterface $cache): self | ||
{ | ||
$this->cache = $cache; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Get Cache | ||
* | ||
* @return ?CacheInterface Cache Object | ||
*/ | ||
public function getCache(): ?CacheInterface | ||
{ | ||
return $this->cache; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RomansTest\Cache; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Psr\Cache\CacheItemPoolInterface as CacheInterface; | ||
use Romans\Cache\CacheAwareTrait; | ||
|
||
/** | ||
* Cache Aware Trait Test | ||
*/ | ||
class CacheAwareTraitTest extends TestCase | ||
{ | ||
/** | ||
* Test Cache | ||
*/ | ||
public function testCache(): void | ||
{ | ||
$cache = $this->createMock(CacheInterface::class); | ||
$element = $this->getMockForTrait(CacheAwareTrait::class); | ||
|
||
$this->assertNull($element->getCache()); | ||
$this->assertFalse($element->hasCache()); | ||
|
||
$this->assertSame($element, $element->setCache($cache)); | ||
$this->assertSame($cache, $element->getCache()); | ||
$this->assertTrue($element->hasCache()); | ||
|
||
$this->assertSame($element, $element->setCache(null)); | ||
$this->assertNull($element->getCache()); | ||
$this->assertFalse($element->hasCache()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.