コード例 #1
0
ファイル: FeatureContext.php プロジェクト: ruian/KnpBundles
 /**
  * @Given /^the site has following users:$/
  */
 public function theSiteHasFollowingUsers(TableNode $table)
 {
     $entityManager = $this->getEntityManager();
     $this->users = array();
     foreach ($table->getHash() as $row) {
         $user = new Entity\User();
         $user->fromArray(array('name' => $row['name'], 'score' => 0));
         $entityManager->persist($user);
         $this->users[$user->getName()] = $user;
     }
     $entityManager->flush();
 }
コード例 #2
0
ファイル: UserProvider.php プロジェクト: ruian/KnpBundles
 public function loadUserByUsername($username)
 {
     $user = $this->em->getRepository('KnpBundlesBundle:User')->findOneByName($username);
     if (!$user) {
         $user = new User();
         $user->setName($username);
         // Get GitHub user
         $user = $this->updater->getOrCreateUser($username);
         $this->em->persist($user);
         $this->em->flush();
     }
     return $user;
 }
コード例 #3
0
ファイル: UserTest.php プロジェクト: ruian/KnpBundles
 public function testUpdateBadUrl()
 {
     $output = $this->getMock('Symfony\\Component\\Console\\Output\\OutputInterface');
     $data = array('blog' => 'knplabs.com');
     $github = $this->getMock('Github_Client', array('getUserApi'));
     $githubUserApi = $this->getMock('Github_Api_User', array('show'), array($github));
     $githubUserApi->expects($this->any())->method('show')->with($this->equalTo('lorem'))->will($this->returnValue($data));
     $github->expects($this->any())->method('getUserApi')->will($this->returnValue($githubUserApi));
     $userEntity = new UserEntity();
     $userEntity->setName('lorem');
     $githubUser = new GithubUser($github, $output);
     $ret = $githubUser->update($userEntity);
     $this->assertEquals('http://knplabs.com', $userEntity->getBlog());
 }
コード例 #4
0
ファイル: data.php プロジェクト: ruian/KnpBundles
 public function load($manager)
 {
     $users = array();
     $trilean = array(true, false, null);
     $i = 0;
     foreach ($this->names as $name => $fullName) {
         $i++;
         $user = new Entity\User();
         $user->fromArray(array('name' => $name, 'email' => strtolower(str_replace(' ', '.', $fullName)) . '@foomail.bar', 'fullName' => $fullName, 'company' => $i % 2 ? 'Company ' . $i : null, 'location' => $i % 2 ? 'Location ' . $i : null, 'blog' => $i % 2 ? 'blog' . $i . '.com' : null, 'score' => 0));
         $manager->persist($user);
         $users[] = $user;
     }
     foreach ($users as $i => $user) {
         $contributors = array();
         $contributors[] = isset($users[$i + 1]) ? $users[$i + 1] : $users[0];
         $contributors[] = isset($users[$i - 1]) ? $users[$i - 1] : $users[count($users) - 1];
         $contributor = array_pop($contributors);
         $bundle = new Entity\Bundle();
         $bundle->fromArray(array('name' => ucfirst($user->getName()) . 'FooBundle', 'username' => $user->getName(), 'user' => $user, 'description' => 'Description of my bundle', 'homepage' => $i % 2 ? 'Bundle' . $i . '.com' : null, 'readme' => str_repeat("README of the bundle number " . $i . "\n", 20), 'tags' => $i % 2 ? array('1.0', '1.1') : array(), 'usesTravisCi' => $i % 2 ? false : true, 'composerName' => $i % 2 ? null : 'knplabs/knp-menu-bundle', 'travisCiBuildStatus' => $i % 2 == 0 ? $trilean[$i % 3] : null, 'nbFollowers' => $i * 10, 'nbForks' => $i, 'lastCommitAt' => new \DateTime('-' . $i * 4 . ' day'), 'lastCommits' => array(array('author' => array('name' => $contributor->getFullName(), 'login' => $contributor->getName(), 'email' => $contributor->getEmail()), 'url' => 'http://github.com', 'committed_date' => '2010-05-16T09:58:32-09:00', 'authored_date' => '2010-05-16T09:58:32-09:00', 'message' => 'Fix something on this ' . 'Bundle'), array('author' => array('name' => $user->getFullName(), 'login' => $user->getName(), 'email' => $user->getEmail()), 'url' => 'http://github.com', 'committed_date' => '2010-05-16T09:58:32-07:00', 'authored_date' => '2010-05-16T09:58:32-07:00', 'message' => 'Commit something on this bundle')), 'isFork' => false, 'contributors' => array($contributor)));
         $manager->persist($bundle);
         // Add some scores for bundles
         $today = new \DateTime();
         // We add a various number of scores for a given bundle
         $daysBefore = crc32($bundle->getName() . '-days') % 50;
         $maxScore = crc32($bundle->getName()) % 50;
         $previousScore = $maxScore;
         while ($daysBefore-- > 0) {
             $date = clone $today;
             $date->sub(new \DateInterval('P' . $daysBefore . 'D'));
             $score = new Entity\Score();
             $score->setBundle($bundle);
             $score->setValue($previousScore + $daysBefore);
             $score->setDate($date);
             $manager->persist($score);
             $previousScore = $score->getValue();
         }
     }
     $manager->flush();
 }
コード例 #5
0
ファイル: User.php プロジェクト: ruian/KnpBundles
 public function update(Entity\User $user)
 {
     try {
         $data = $this->github->getUserApi()->show($user->getName());
     } catch (\Github_HttpClient_Exception $e) {
         if (404 == $e->getCode()) {
             // User has been removed
             return false;
         }
         return true;
     }
     $user->setEmail(isset($data['email']) ? $data['email'] : null);
     $user->setGravatarHash(isset($data['gravatar_id']) ? $data['gravatar_id'] : null);
     $user->setFullName(isset($data['name']) ? $data['name'] : null);
     $user->setCompany(isset($data['company']) ? $data['company'] : null);
     $user->setLocation(isset($data['location']) ? $data['location'] : null);
     $user->setBlog(isset($data['blog']) ? $this->fixUrl($data['blog']) : null);
     return true;
 }