diff --git a/src/ArrayCache.php b/src/ArrayCache.php index 03dcc15..ff2a06d 100644 --- a/src/ArrayCache.php +++ b/src/ArrayCache.php @@ -20,10 +20,12 @@ public function get($key) public function set($key, $value) { $this->data[$key] = $value; + return new Promise\FulfilledPromise(true); } public function remove($key) { unset($this->data[$key]); + return new Promise\FulfilledPromise(true); } } diff --git a/src/CacheInterface.php b/src/CacheInterface.php index fd5f2d5..34211a2 100644 --- a/src/CacheInterface.php +++ b/src/CacheInterface.php @@ -2,12 +2,22 @@ namespace React\Cache; +use React\Promise\PromiseInterface; + interface CacheInterface { - // @return React\Promise\PromiseInterface + /** + * @return PromiseInterface + */ public function get($key); + /** + * @return PromiseInterface + */ public function set($key, $value); + /** + * @return PromiseInterface + */ public function remove($key); } diff --git a/tests/ArrayCacheTest.php b/tests/ArrayCacheTest.php index eec3739..383490b 100644 --- a/tests/ArrayCacheTest.php +++ b/tests/ArrayCacheTest.php @@ -6,6 +6,9 @@ class ArrayCacheTest extends TestCase { + /** + * @var ArrayCache + */ private $cache; public function setUp() @@ -27,9 +30,17 @@ public function getShouldRejectPromiseForNonExistentKey() /** @test */ public function setShouldSetKey() { - $this->cache + $setPromise = $this->cache ->set('foo', 'bar'); + $mock = $this->createCallableMock(); + $mock + ->expects($this->once()) + ->method('__invoke') + ->with($this->identicalTo(true)); + + $setPromise->then($mock); + $success = $this->createCallableMock(); $success ->expects($this->once()) @@ -47,9 +58,17 @@ public function removeShouldRemoveKey() $this->cache ->set('foo', 'bar'); - $this->cache + $removePromise = $this->cache ->remove('foo'); + $mock = $this->createCallableMock(); + $mock + ->expects($this->once()) + ->method('__invoke') + ->with($this->identicalTo(true)); + + $removePromise->then($mock); + $this->cache ->get('foo') ->then(