From 7019c7cf6c6af39c0f458769e20c3f9306477943 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 31 Dec 2015 11:24:46 +0100 Subject: Add tagged services for import - list services in /import - add url to import service - ImportBundle routing are now prefixed by /import - optimize flush in each import (flushing each 20 contents) - improve design of each import - add more tests --- .../ImportBundle/Tests/Import/ImportChainTest.php | 21 ++++++++++ .../Tests/Import/ImportCompilerPassTest.php | 47 ++++++++++++++++++++++ .../ImportBundle/Tests/Import/PocketImportTest.php | 3 +- .../Tests/Import/WallabagV1ImportTest.php | 3 +- 4 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 src/Wallabag/ImportBundle/Tests/Import/ImportChainTest.php create mode 100644 src/Wallabag/ImportBundle/Tests/Import/ImportCompilerPassTest.php (limited to 'src/Wallabag/ImportBundle/Tests/Import') diff --git a/src/Wallabag/ImportBundle/Tests/Import/ImportChainTest.php b/src/Wallabag/ImportBundle/Tests/Import/ImportChainTest.php new file mode 100644 index 00000000..702d2a9b --- /dev/null +++ b/src/Wallabag/ImportBundle/Tests/Import/ImportChainTest.php @@ -0,0 +1,21 @@ +getMockBuilder('Wallabag\ImportBundle\Import\ImportInterface') + ->disableOriginalConstructor() + ->getMock(); + + $importChain = new ImportChain(); + $importChain->addImport($import, 'alias'); + + $this->assertCount(1, $importChain->getAll()); + $this->assertEquals($import, $importChain->getAll()['alias']); + } +} diff --git a/src/Wallabag/ImportBundle/Tests/Import/ImportCompilerPassTest.php b/src/Wallabag/ImportBundle/Tests/Import/ImportCompilerPassTest.php new file mode 100644 index 00000000..bd62ab3b --- /dev/null +++ b/src/Wallabag/ImportBundle/Tests/Import/ImportCompilerPassTest.php @@ -0,0 +1,47 @@ +process($container); + + $this->assertNull($res); + } + + public function testProcess() + { + $container = new ContainerBuilder(); + $container + ->register('wallabag_import.chain') + ->setPublic(false) + ; + + $container + ->register('foo') + ->addTag('wallabag_import.import', array('alias' => 'pocket')) + ; + + $this->process($container); + + $this->assertTrue($container->hasDefinition('wallabag_import.chain')); + + $definition = $container->getDefinition('wallabag_import.chain'); + $this->assertTrue($definition->hasMethodCall('addImport')); + + $calls = $definition->getMethodCalls(); + $this->assertEquals('pocket', $calls[0][1][1]); + } + + protected function process(ContainerBuilder $container) + { + $repeatedPass = new ImportCompilerPass(); + $repeatedPass->process($container); + } +} diff --git a/src/Wallabag/ImportBundle/Tests/Import/PocketImportTest.php b/src/Wallabag/ImportBundle/Tests/Import/PocketImportTest.php index cf706fa9..6ee70db0 100644 --- a/src/Wallabag/ImportBundle/Tests/Import/PocketImportTest.php +++ b/src/Wallabag/ImportBundle/Tests/Import/PocketImportTest.php @@ -74,7 +74,8 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase $pocketImport = $this->getPocketImport(); $this->assertEquals('Pocket', $pocketImport->getName()); - $this->assertEquals('This importer will import all your Pocket data.', $pocketImport->getDescription()); + $this->assertNotEmpty($pocketImport->getUrl()); + $this->assertContains('This importer will import all your Pocket data.', $pocketImport->getDescription()); } public function testOAuthRequest() diff --git a/src/Wallabag/ImportBundle/Tests/Import/WallabagV1ImportTest.php b/src/Wallabag/ImportBundle/Tests/Import/WallabagV1ImportTest.php index fc66d402..8a8eb3fa 100644 --- a/src/Wallabag/ImportBundle/Tests/Import/WallabagV1ImportTest.php +++ b/src/Wallabag/ImportBundle/Tests/Import/WallabagV1ImportTest.php @@ -39,7 +39,8 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase $wallabagV1Import = $this->getWallabagV1Import(); $this->assertEquals('Wallabag v1', $wallabagV1Import->getName()); - $this->assertEquals('This importer will import all your wallabag v1 articles.', $wallabagV1Import->getDescription()); + $this->assertNotEmpty($wallabagV1Import->getUrl()); + $this->assertContains('This importer will import all your wallabag v1 articles.', $wallabagV1Import->getDescription()); } public function testImport() -- cgit v1.2.3