/** * @dataProvider provideForGetPosts */ public function testGetPosts($expectedPosts, $html) { $posts = HtmlExtractor::getPosts($html); $this->assertCount(count($expectedPosts), $posts); foreach ($posts as $i => $post) { $this->assertEquals($expectedPosts[$i], $post); } }
protected function execute(InputInterface $input, OutputInterface $output) { $app = $this->getHelper("app")->getApplication(); $page = 0; $nb = 0; while ($nb < self::ITEMS_TO_IMPORT) { $html = $this->_download($page, $output); $posts = HtmlExtractor::getPosts($html); if ($output->isVerbose()) { $output->writeln('<info>Found ' . count($posts) . ' posts</info>'); } $nb += count($posts); foreach ($posts as $post) { try { $app['db']->insert('post', $post); } catch (\Doctrine\DBAL\Exception\UniqueConstraintViolationException $e) { if ($output->isVeryVerbose()) { $output->writeln('<info>Post ' . $post['id'] . ' is already in db</info>'); } } } $page++; } }