public function it_will_fetch_user_details_from_github($authenticatedClientFactory, $githubUserDataFactory, GithubUserDataInterface $githubUser, User $user, Client $client, ApiUser $userApi, GithubUserData $githubUserData)
 {
     $githubUser->getUsername()->willReturn('username');
     $authenticatedClientFactory->create($user)->willReturn($client);
     $client->api('user')->willReturn($userApi);
     $userApi->show('username')->willReturn(['data']);
     $githubUserDataFactory->create(['data'])->willReturn($githubUserData);
     $this->fetch($githubUser, $user)->shouldReturn($githubUserData);
 }
Ejemplo n.º 2
0
 public function it_will_return_new_entity_if_no_entity_found($repository, $factory, $em, GithubUserDataInterface $userValueObject, GithubUser $githubUserEntity)
 {
     $userValueObject->getUsername()->willReturn('username');
     $repository->findOneByUsername('username')->willReturn(null);
     $factory->createFromValueObject($userValueObject)->willReturn($githubUserEntity);
     $em->persist($githubUserEntity)->shouldBeCalled();
     $em->flush()->shouldBeCalled();
     $this->getOrCreate($userValueObject)->shouldReturn($githubUserEntity);
 }
Ejemplo n.º 3
0
 /**
  * @param GithubUserData|GithubUserDataInterface $remote
  * @param GithubUser                             $entity
  *
  * @return bool
  */
 public function map(GithubUserDataInterface $remote, GithubUser $entity)
 {
     if (null !== $remote->getGithubId()) {
         $entity->setGithubId($remote->getGithubId());
     }
     $entity->setUsername($remote->getUsername());
     if (null !== $remote->getEmail()) {
         $entity->setEmail($remote->getEmail());
     }
     if (null !== $remote->getName()) {
         $entity->setName($remote->getName());
     }
     if (null !== $remote->getAvatarUrl()) {
         $entity->setAvatarUrl($remote->getAvatarUrl());
     }
     return true;
 }
Ejemplo n.º 4
0
 public function it_will_map_property_values_from_remote_to_entity_even_if_only_username_exists(GithubUserDataInterface $remote, GithubUser $entity, $username)
 {
     $remote->getGithubId()->willReturn(null);
     $remote->getUsername()->willReturn($username);
     $remote->getEmail()->willReturn(null);
     $remote->getName()->willReturn(null);
     $remote->getAvatarUrl()->willReturn(null);
     $entity->setGithubId(Argument::any())->shouldNotBeCalled();
     $entity->setUsername($username)->shouldBeCalled();
     $entity->setEmail(Argument::any())->shouldNotBeCalled();
     $entity->setName(Argument::any())->shouldNotBeCalled();
     $entity->setAvatarUrl(Argument::any())->shouldNotBeCalled();
     $this->map($remote, $entity)->shouldReturn(true);
 }
Ejemplo n.º 5
0
 /**
  * @param GithubUserDataInterface $githubUser
  * @param User                    $user
  *
  * @return mixed
  */
 public function fetch(GithubUserDataInterface $githubUser, User $user)
 {
     $client = $this->createClient($user);
     $remoteData = $client->api('user')->show($githubUser->getUsername());
     return $this->githubUserDataFactory->create($remoteData);
 }
Ejemplo n.º 6
0
 /**
  * @param GithubUserDataInterface $userValueObject
  *
  * @return mixed
  */
 public function get(GithubUserDataInterface $userValueObject)
 {
     return $this->repository->findOneByUsername($userValueObject->getUsername());
 }