Skip to content

Commit

Permalink
[5.7] Add missing() method to the Cache (#26351)
Browse files Browse the repository at this point in the history
* [5.7] Added `missing()` method to the Cache\Repository and its Facade

* [5.7] Removed the `missing()` method from the `Cache\Repository` contract
  • Loading branch information
dmitry-ivanov authored and taylorotwell committed Nov 2, 2018
1 parent 468754a commit a481780
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Illuminate/Cache/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ public function has($key)
return ! is_null($this->get($key));
}

/**
* Determine if an item doesn't exist in the cache.
*
* @param string $key
* @return bool
*/
public function missing($key)
{
return ! $this->has($key);
}

/**
* Retrieve an item from the cache by key.
*
Expand Down
1 change: 1 addition & 0 deletions src/Illuminate/Support/Facades/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/**
* @method static \Illuminate\Contracts\Cache\Repository store(string|null $name = null)
* @method static bool has(string $key)
* @method static bool missing(string $key)
* @method static mixed get(string $key, mixed $default = null)
* @method static mixed pull(string $key, mixed $default = null)
* @method static void put(string $key, $value, \DateTimeInterface|\DateInterval|float|int $minutes)
Expand Down
10 changes: 10 additions & 0 deletions tests/Cache/CacheRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ public function testHasMethod()
$this->assertFalse($repo->has('foo'));
}

public function testMissingMethod()
{
$repo = $this->getRepository();
$repo->getStore()->shouldReceive('get')->once()->with('foo')->andReturn(null);
$repo->getStore()->shouldReceive('get')->once()->with('bar')->andReturn('bar');

$this->assertTrue($repo->missing('foo'));
$this->assertFalse($repo->missing('bar'));
}

public function testRememberMethodCallsPutAndReturnsDefault()
{
$repo = $this->getRepository();
Expand Down

0 comments on commit a481780

Please sign in to comment.