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);
 }
Exemplo 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);
 }
Exemplo n.º 3
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);
 }
Exemplo n.º 4
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;
 }
Exemplo 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);
 }
Exemplo n.º 6
0
 /**
  * @param GithubUserDataInterface $userValueObject
  *
  * @return mixed
  */
 public function get(GithubUserDataInterface $userValueObject)
 {
     return $this->repository->findOneByUsername($userValueObject->getUsername());
 }