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++; } }
/** * @dataProvider provideForGetPost */ public function testGetPost($expectedPost, $text) { $post = HtmlExtractor::getPost($text); $this->assertEquals($expectedPost, $post); }