MongolidLaravel\LaravelCacheComponent::get PHP Method

get() public method

Retrieve an item from the cache by key.
public get ( string $key ) : mixed
$key string Cache key of the item to be retrieved.
return mixed
    public function get(string $key)
    {
        $result = $this->laravelCache->get($key, null);
        if (is_array($result)) {
            return $this->serializer->unconvert($result);
        }
        return $result;
    }

Usage Example

 public function testShouldGet()
 {
     // Set
     $cacheRepo = m::mock(Repository::class);
     $serializer = m::mock(Serializer::class);
     $component = new LaravelCacheComponent($cacheRepo, $serializer);
     $key = 'foo';
     $value = 'bar';
     // Expectations
     $cacheRepo->shouldReceive('get')->once()->with($key, null)->andReturn($value);
     // Assertion
     $this->assertEquals($value, $component->get($key));
 }
LaravelCacheComponent