public function setUp() { $kernel = static::createKernel(); $kernel->boot(); if ($kernel->getContainer()->getParameter('database_driver') == 'pdo_sqlite') { $this->markTestSkipped("The SQLite does not support joins."); } $this->em = $kernel->getContainer()->get('knp_bundles.entity_manager'); $fileLocator = new FileLocator(__DIR__ . '/fixtures/'); $path = $fileLocator->locate('trending-bundles.yml'); $data = Yaml::parse($path); $developer = new Developer(); $developer->setName('someName'); $developer->setScore(0); $this->em->persist($developer); foreach ($data['bundles'] as $bundleName => $bundleData) { $bundle = new Bundle('vendor/' . $bundleName); $bundle->setDescription('some description'); $bundle->setScore(100); $bundle->setOwner($developer); foreach ($bundleData['scores'] as $scoreData) { $bundle->setDescription(md5(time() . serialize($scoreData))); $score = new Score(); $score->setDate(new \DateTime($scoreData['date'])); $score->setBundle($bundle); $score->setValue($scoreData['value']); $this->em->persist($score); } $this->em->persist($bundle); } $this->em->flush(); }
/** * {@inheritDoc} */ public function import($name, $update = true) { $developer = new EntityDeveloper(); $developer->setName($name); if ($update && !$this->update($developer)) { return false; } return $developer; }
public function testRecommandationsScoreUpdate() { $bundle = new Bundle(); for ($index = 0; $index < 5; ++$index) { $user = new Developer(); $user->setName('Contributor #' . ($index + 1)); $bundle->addRecommender($user); } $tester = new KnpBundlesListener(); $tester->updateScore($bundle); $bundle->recalculateScore(); $this->assertEquals(25, $bundle->getScore()); }
public function testUpdateBadUrl() { $output = $this->getMock('Symfony\\Component\\Console\\Output\\OutputInterface'); $data = array('blog' => 'knplabs.com'); $github = $this->getMock('Github\\Client', array('api')); $githubDeveloperApi = $this->getMock('Github\\Api\\User', array('show'), array($github)); $githubDeveloperApi->expects($this->any())->method('show')->with($this->equalTo('lorem'))->will($this->returnValue($data)); $github->expects($this->any())->method('api')->with('user')->will($this->returnValue($githubDeveloperApi)); $userEntity = new DeveloperEntity(); $userEntity->setName('lorem'); $githubDeveloper = new GithubDeveloper($github, $output); $githubDeveloper->update($userEntity); $this->assertEquals('http://knplabs.com', $userEntity->getUrl()); }