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
 }
Beispiel #2
0
 /**
  * Get a default map of loaders
  *
  * @return LoadersMap
  */
 protected static function getDefaultLoadersMap()
 {
     return LoadersMap::construct(['profile' => self::getAllFields()->getSupportedFields()]);
 }
Beispiel #3
0
 public function testReAddField()
 {
     $loadersMap = new LoadersMap();
     $loadersMap->loader('customLoader')->addField('field1');
     $this->assertEquals('customLoader', $loadersMap->getLoaderForField('field1'));
     $loadersMap->loader('customLoader2')->readdField('field1');
     $this->assertEquals('customLoader2', $loadersMap->getLoaderForField('field1'));
 }