setLastCommitAt() public method

Set lastCommitAt
public setLastCommitAt ( DateTime $lastCommitAt )
$lastCommitAt DateTime
Beispiel #1
0
 public function testGlobalScore()
 {
     $dispatcher = new EventDispatcher();
     $testers = array('Activity', 'Composer', 'Followers', 'KnpBundles', 'Readme', 'Travis');
     foreach ($testers as $testerClass) {
         $fqcn = sprintf('\\Knp\\Bundle\\KnpBundlesBundle\\EventListener\\Scoring\\%sListener', $testerClass);
         $tester = new $fqcn();
         $dispatcher->addListener(BundleEvent::UPDATE_SCORE, array($tester, 'onScoreUpdate'));
     }
     $bundle = new Bundle();
     // activity (+4)
     $bundle->setLastCommitAt(new \DateTime('-10days'));
     // composer (+5)
     $bundle->setComposerName('bundle-composer-name');
     // followers (+10)
     $bundle->setNbFollowers(10);
     // recommendation (+5)
     $bundle->addRecommender(new Developer());
     // readme (+5)
     $bundle->setReadme(str_repeat('-', 500));
     // travis (+10)
     $bundle->setUsesTravisCi(true);
     $bundle->setTravisCiBuildStatus(true);
     $dispatcher->dispatch(BundleEvent::UPDATE_SCORE, new BundleEvent($bundle));
     $bundle->recalculateScore();
     $this->assertEquals(39, $bundle->getScore());
 }
Beispiel #2
0
 /**
  * @test
  */
 public function shouldNotHaveChangesWithOnlyChangedScore()
 {
     $bundle = new Bundle('knplabs/KnpMenuBundle');
     $bundle->setScore(1000);
     $bundle->setReadme('readme number one');
     $bundle->setLastCommitAt(new \DateTime('-10 day'));
     $bundle->setNbFollowers(100);
     $bundle->setNbForks(10);
     $beforeChange = $bundle->getStatusHash();
     $bundle->setScore(1100);
     $afterChange = $bundle->getStatusHash();
     $this->assertEquals($beforeChange, $afterChange);
 }
 public function testActivityScoreDetail()
 {
     $bundle = new Bundle();
     $bundle->setLastCommitAt(new \DateTime('-10days'));
     $tester = new ActivityListener();
     $tester->updateScore($bundle);
     $bundle->recalculateScore();
     $this->assertEquals(4, $bundle->getScore());
     $oldBundle = new Bundle();
     $oldBundle->setLastCommitAt(new \DateTime('-45days'));
     $tester->updateScore($oldBundle);
     $oldBundle->recalculateScore();
     $this->assertEquals(0, $oldBundle->getScore());
 }
Beispiel #4
0
 /**
  * @Given /^the site has following bundles:$/
  */
 public function theSiteHasFollowingBundles(TableNode $table)
 {
     $entityManager = $this->getEntityManager();
     $this->bundles = array();
     foreach ($table->getHash() as $row) {
         if (isset($this->developers[$row['username']])) {
             $owner = $this->developers[$row['username']];
         } elseif (isset($this->organizations[$row['username']])) {
             $owner = $this->organizations[$row['username']];
         } else {
             continue;
         }
         $bundle = new Entity\Bundle();
         $bundle->fromArray(array('name' => $row['name'], 'owner' => $owner, 'ownerName' => $owner->getName(), 'description' => $row['description'], 'readme' => isset($row['readme']) ? $row['readme'] : '', 'state' => isset($row['state']) ? $row['state'] : Entity\Bundle::STATE_UNKNOWN));
         if (isset($row['license'])) {
             $bundle->setLicenseType($row['license']);
         }
         if (isset($row['createdAt'])) {
             $bundle->setCreatedAt(new \DateTime($row['createdAt']));
         }
         if (isset($row['lastCommitAt'])) {
             $bundle->setLastCommitAt(new \DateTime($row['lastCommitAt']));
         }
         $bundle->setScore($row['score']);
         $versionsHistory['dependencies']['dev-master'] = array('name' => 'friendsofsymfony/user-bundle', 'extra' => array('branch-alias' => array('dev-master' => '2.0.x-dev')), 'require' => array('php' => '>=5.3.2'), 'require-dev' => '', 'suggest' => '');
         $bundle->setVersionsHistory($versionsHistory);
         $this->setPrivateProperty($bundle, "trend1", $row['trend1']);
         if (isset($row['recommendedBy'])) {
             $ownerNames = explode(',', $row['recommendedBy']);
             foreach ($ownerNames as $ownerName) {
                 $owner = $this->developers[trim($ownerName)];
                 $bundle->addRecommender($owner);
                 $owner->addRecommendedBundle($bundle);
                 $entityManager->persist($owner);
             }
         }
         $entityManager->persist($bundle);
         $this->bundles[$bundle->getName()] = $bundle;
     }
     $entityManager->flush();
 }
Beispiel #5
0
 protected function makeBundle($manager, Entity\Owner $owner, $i, $contributor = null)
 {
     $trilean = array(true, false, null);
     $bundle = new Entity\Bundle();
     $bundle->fromArray(array('name' => ucfirst($owner->getName()) . $i . 'FooBundle', 'description' => $this->descriptions[mt_rand(0, 4)], 'homepage' => $i % 2 ? 'Bundle' . $i . '.com' : null, 'readme' => str_replace('__BUNDLE__', "the bundle number: {$i}", $this->readme), 'usesTravisCi' => $i % 2 ? false : true, 'composerName' => $i % 2 ? null : 'knplabs/knp-menu-bundle', 'versionsHistory' => array('symfony' => array('dev-master' => '2.1.*', '1.2.0' => '2.0.*', '1.1.0' => '2.*'), 'dependencies' => array('dev-master' => array('name' => 'friendsofsymfony/user-bundle', 'extra' => array('branch-alias' => array('dev-master' => '2.0.x-dev')), 'require' => array('php' => '>=5.3.2', 'symfony/framework-bundle' => '>=2.1,<2.3-dev', 'symfony/security-bundle' => '>=2.1,<2.3-dev'), 'require-dev' => array('twig/twig' => '*', 'doctrine/doctrine-bundle' => '*', 'swiftmailer/swiftmailer' => '*', 'willdurand/propel-typehintable-behavior' => 'dev-master', 'symfony/validator' => '2.1.*', 'symfony/yaml' => '2.1.*'), 'suggest' => array('doctrine/couchdb-odm-bundle' => '*', 'doctrine/doctrine-bundle' => '*', 'doctrine/mongodb-odm-bundle' => '*')), '1.2.x-dev' => array('name' => 'friendsofsymfony/user-bundle', 'require' => array('php' => '>=5.3.2', 'symfony/framework-bundle' => '>=2.1,<2.3-dev', 'symfony/security-bundle' => '>=2.1,<2.3-dev'), 'require-dev' => '', 'suggest' => ''))), 'state' => $this->states[mt_rand(0, 3)], 'license' => $i % 4 == 0 ? 'Some pseudo license data' : null, 'licenseType' => $i % 3 == 0 ? $this->licenses[mt_rand(0, 2)] : null, 'travisCiBuildStatus' => $i % 2 == 0 ? $trilean[$i % 3] : null, 'nbFollowers' => $i * 10, 'nbForks' => $i, 'isFork' => false, 'contributors' => $contributor ? array($contributor) : array(), 'canonicalConfig' => $i % 2 == 0 ? $this->canonicalConfigDump : null, 'nbRecommenders' => rand(0, 90)));
     $commits = array(array('date' => '2010-05-16T09:58:32-09:00', 'author' => $owner instanceof Entity\Developer ? $owner->getName() : 'Random Person', 'message' => 'Fix something on this Bundle'), array('date' => '2010-05-16T09:58:32-07:00', 'author' => 'Fake Name', 'message' => 'Commit something on this bundle'));
     foreach ($commits as $commit) {
         $lastCommitAt = new \DateTime();
         $lastCommitAt->setTimestamp(strtotime($commit['date']));
         $bundle->setLastCommitAt($lastCommitAt);
         $activity = new Entity\Activity();
         $activity->setType(Entity\Activity::ACTIVITY_TYPE_COMMIT);
         $activity->setMessage(strtok($commit['message'], "\n\r"));
         $activity->setCreatedAt($lastCommitAt);
         $activity->setBundle($bundle);
         if ($owner->getName() == $commit['author']) {
             $owner->setLastCommitAt($lastCommitAt);
             $activity->setDeveloper($owner);
             $activity->setBundleOwnerName(strtolower($owner->getName()));
         } else {
             $activity->setAuthor($commit['author']);
             $activity->setBundleOwnerName(strtolower($commit['author']));
         }
         $manager->persist($activity);
     }
     $owner->addBundle($bundle);
     return $bundle;
 }
Beispiel #6
0
 public function testGetDaysSinceLastCommit()
 {
     $bundle = new Bundle('knplabs/KnpMenuBundle');
     $bundle->setLastCommitAt(new \Datetime('-31 days'));
     $this->assertEquals(31, $bundle->getDaysSinceLastCommit());
 }