Exemplo n.º 1
0
 public function testLazyLoadGet()
 {
     $constructorArgs = [FieldsValues::construct([ExtractorInterface::FIELD_UNIQUE_ID => 123, ExtractorInterface::FIELD_USERNAME]), NormalizersMap::construct([ExtractorInterface::FIELD_UNIQUE_ID => ExtractorInterface::FIELD_UNIQUE_ID])->method(ExtractorInterface::FIELD_USERNAME, 'username'), LoadersMap::construct(['id' => [ExtractorInterface::FIELD_UNIQUE_ID], 'profile' => [ExtractorInterface::FIELD_USERNAME]])];
     $profileData = ['data' => ['nickname' => 'johnnydonny']];
     $extractor = $this->getMock('\\OAuth\\UserData\\Extractor\\LazyExtractor', ['idLoader', 'uniqueIdNormalizer', 'profileLoader', 'usernameNormalizer'], $constructorArgs);
     $extractor->expects($this->never())->method('idLoader');
     $extractor->expects($this->never())->method('uniqueIdNormalizer');
     $extractor->expects($this->once())->method('profileLoader')->with()->willReturn($profileData);
     $extractor->expects($this->once())->method('usernameNormalizer')->with($profileData)->willReturn($profileData['data']['nickname']);
     /**
      * @var \OAuth\UserData\Extractor\LazyExtractor $extractor
      */
     $this->assertEquals(123, $extractor->getUniqueId());
     // prefetched field, does not trigger loader and normalizer
     $this->assertEquals('johnnydonny', $extractor->getUsername());
     // triggers the loader and the normalizer
     $this->assertEquals('johnnydonny', $extractor->getUsername());
     // does not trigger them again
 }
Exemplo n.º 2
0
 /**
  * Get a default normalizers map
  *
  * @return NormalizersMap
  */
 protected static function getDefaultNormalizersMap()
 {
     return NormalizersMap::forMethods(self::getAllFields()->getSupportedFields());
 }
Exemplo n.º 3
0
 public function testPrependByPathContext()
 {
     $normalizersMap = NormalizersMap::construct()->path('field1', 'path')->prependByPathContext('someContext')->path('field2', 'path');
     $this->assertEquals(['type' => NormalizersMap::TYPE_ARRAY_PATH, 'path' => 'someContext.path', 'defaultValue' => null, 'contextPath' => 'someContext.', 'pathWithoutContext' => 'path'], $normalizersMap->getNormalizerForField('field1'));
     $this->assertEquals(['type' => NormalizersMap::TYPE_ARRAY_PATH, 'path' => 'someContext.path', 'defaultValue' => null, 'contextPath' => 'someContext.', 'pathWithoutContext' => 'path'], $normalizersMap->getNormalizerForField('field2'));
 }