/** * @test */ public function shouldRetrieveTokenAndCacheIt() { $credentials = new Credentials("id", "secret", "username", "password"); $cacheKey = (string) $credentials; $token = new AccessToken("foo", "http://", "http://foo/some-id", "bar", "1457566074818", "foobar"); $this->tokenProvider->shouldReceive("getToken")->once()->with($credentials)->andReturn($token); $this->arrayCache->shouldReceive("contains")->once()->with($cacheKey)->andReturn(false); $this->arrayCache->shouldReceive("save")->once()->with($cacheKey, $token); $this->arrayCache->shouldReceive("fetch")->once()->with((string) $credentials)->andReturn($token); $this->cachingTokenProvider->getToken($credentials); }