コード例 #1
0
 /** @dataProvider provideShouldNotifyTokenCallback */
 public function testShouldNotifyTokenCallback(callable $tokenCallback)
 {
     $prefix = 'test_prefix-';
     $cacheKey = 'myKey';
     $token = '1/abcdef1234567890';
     $authResult = ['access_token' => $token];
     $this->mockCacheItem->expects($this->any())->method('get')->will($this->returnValue(null));
     $this->mockCache->expects($this->any())->method('getItem')->with($this->equalTo($prefix . $cacheKey))->will($this->returnValue($this->mockCacheItem));
     $this->mockFetcher->expects($this->any())->method('getCacheKey')->will($this->returnValue($cacheKey));
     $this->mockFetcher->expects($this->once())->method('fetchAuthToken')->will($this->returnValue($authResult));
     SubscriberCallback::$expectedKey = $this->getValidKeyName($prefix . $cacheKey);
     SubscriberCallback::$expectedValue = $token;
     SubscriberCallback::$called = false;
     // Run the test
     $a = new AuthTokenSubscriber($this->mockFetcher, ['prefix' => $prefix], $this->mockCache, null, $tokenCallback);
     $client = new Client();
     $request = $client->createRequest('GET', 'http://testing.org', ['auth' => 'google_auth']);
     $before = new BeforeEvent(new Transaction($client, $request));
     $a->onBefore($before);
     $this->assertTrue(SubscriberCallback::$called);
 }
コード例 #2
0
 public function testShouldSaveValueInCacheWithSpecifiedPrefix()
 {
     $token = '1/abcdef1234567890';
     $authResult = ['access_token' => $token];
     $cacheKey = 'myKey';
     $prefix = 'test_prefix:';
     $this->mockCache->expects($this->any())->method('get')->will($this->returnValue(null));
     $this->mockCache->expects($this->once())->method('set')->with($this->equalTo($prefix . $cacheKey), $this->equalTo($token))->will($this->returnValue(false));
     $this->mockFetcher->expects($this->any())->method('getCacheKey')->will($this->returnValue($cacheKey));
     $this->mockFetcher->expects($this->once())->method('fetchAuthToken')->will($this->returnValue($authResult));
     // Run the test
     $a = new AuthTokenSubscriber($this->mockFetcher, array('prefix' => $prefix), $this->mockCache);
     $client = new Client();
     $request = $client->createRequest('GET', 'http://testing.org', ['auth' => 'google_auth']);
     $before = new BeforeEvent(new Transaction($client, $request));
     $a->onBefore($before);
     $this->assertSame($request->getHeader('Authorization'), 'Bearer 1/abcdef1234567890');
 }