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()); }
public function testTravisBuildStatus() { $bundle = new Bundle(); $tester = new TravisListener(); $bundle->setTravisCiBuildStatus(false); $tester->updateScore($bundle); $bundle->recalculateScore(); $this->assertEquals(0, $bundle->getScore()); $bundle->setTravisCiBuildStatus(true); $tester->updateScore($bundle); $bundle->recalculateScore(); $this->assertEquals(5, $bundle->getScore()); }
/** * Updates repo based on status from travis. * * @param Bundle $bundle * * @return boolean */ public function update(Bundle $bundle) { $this->output->write(' Travis status:'); $response = $this->browser->get('http://travis-ci.org/' . $bundle->getOwnerName() . '/' . $bundle->getName() . '.json'); $status = json_decode($response->getContent(), true); if (JSON_ERROR_NONE === json_last_error()) { $lastBuildAt = new \DateTime(); $lastBuildAt->setTimestamp(strtotime($status['last_build_finished_at'])); // Only execute if date of last build is older than last update of bundle if ($lastBuildAt < $bundle->getUpdatedAt()) { $state = Activity::STATE_UNKNOWN; if (0 === $status['last_build_status']) { $bundle->setTravisCiBuildStatus(true); $state = Activity::STATE_OPEN; $this->output->write(' success'); } elseif (1 === $status['last_build_status']) { $bundle->setTravisCiBuildStatus(false); $state = Activity::STATE_CLOSED; $this->output->write(' failed'); } if (Activity::STATE_UNKNOWN !== $state) { $activity = new Activity(); $activity->setType(Activity::ACTIVITY_TYPE_TRAVIS_BUILD); $activity->setState($state); $activity->setBundle($bundle); return true; } } else { $this->output->write(' skipped'); return true; } } $bundle->setTravisCiBuildStatus(null); $this->output->write(' error'); return false; }