From f808b01692a835673f328d7221ba8c212caa9b61 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 1 Jul 2017 09:52:38 +0200 Subject: Add a real configuration for CS-Fixer --- .../ImportBundle/Import/ChromeImportTest.php | 114 +++++++-------- .../ImportBundle/Import/FirefoxImportTest.php | 114 +++++++-------- .../ImportBundle/Import/ImportChainTest.php | 2 +- .../ImportBundle/Import/ImportCompilerPassTest.php | 2 +- .../ImportBundle/Import/InstapaperImportTest.php | 142 +++++++++---------- .../ImportBundle/Import/PocketImportTest.php | 150 ++++++++++---------- .../ImportBundle/Import/ReadabilityImportTest.php | 114 +++++++-------- .../ImportBundle/Import/WallabagV1ImportTest.php | 156 ++++++++++----------- .../ImportBundle/Import/WallabagV2ImportTest.php | 150 ++++++++++---------- 9 files changed, 472 insertions(+), 472 deletions(-) (limited to 'tests/Wallabag/ImportBundle/Import') diff --git a/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php b/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php index cec19534..5559ac7e 100644 --- a/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php @@ -2,14 +2,14 @@ namespace Tests\Wallabag\ImportBundle\Import; -use Wallabag\ImportBundle\Import\ChromeImport; -use Wallabag\UserBundle\Entity\User; -use Wallabag\CoreBundle\Entity\Entry; -use Wallabag\ImportBundle\Redis\Producer; -use Monolog\Logger; +use M6Web\Component\RedisMock\RedisMockFactory; use Monolog\Handler\TestHandler; +use Monolog\Logger; use Simpleue\Queue\RedisQueue; -use M6Web\Component\RedisMock\RedisMockFactory; +use Wallabag\CoreBundle\Entity\Entry; +use Wallabag\ImportBundle\Import\ChromeImport; +use Wallabag\ImportBundle\Redis\Producer; +use Wallabag\UserBundle\Entity\User; class ChromeImportTest extends \PHPUnit_Framework_TestCase { @@ -19,56 +19,19 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase protected $contentProxy; protected $tagsAssigner; - private function getChromeImport($unsetUser = false, $dispatched = 0) - { - $this->user = new User(); - - $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') - ->disableOriginalConstructor() - ->getMock(); - - $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') - ->disableOriginalConstructor() - ->getMock(); - - $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') - ->disableOriginalConstructor() - ->getMock(); - - $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') - ->disableOriginalConstructor() - ->getMock(); - - $dispatcher - ->expects($this->exactly($dispatched)) - ->method('dispatch'); - - $wallabag = new ChromeImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher); - - $this->logHandler = new TestHandler(); - $logger = new Logger('test', [$this->logHandler]); - $wallabag->setLogger($logger); - - if (false === $unsetUser) { - $wallabag->setUser($this->user); - } - - return $wallabag; - } - public function testInit() { $chromeImport = $this->getChromeImport(); - $this->assertEquals('Chrome', $chromeImport->getName()); + $this->assertSame('Chrome', $chromeImport->getName()); $this->assertNotEmpty($chromeImport->getUrl()); - $this->assertEquals('import.chrome.description', $chromeImport->getDescription()); + $this->assertSame('import.chrome.description', $chromeImport->getDescription()); } public function testImport() { $chromeImport = $this->getChromeImport(false, 1); - $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks'); + $chromeImport->setFilepath(__DIR__ . '/../fixtures/chrome-bookmarks'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -95,13 +58,13 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase $res = $chromeImport->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 1, 'queued' => 0], $chromeImport->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 1, 'queued' => 0], $chromeImport->getSummary()); } public function testImportAndMarkAllAsRead() { $chromeImport = $this->getChromeImport(false, 1); - $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks'); + $chromeImport->setFilepath(__DIR__ . '/../fixtures/chrome-bookmarks'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -133,13 +96,13 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 1, 'queued' => 0], $chromeImport->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 1, 'queued' => 0], $chromeImport->getSummary()); } public function testImportWithRabbit() { $chromeImport = $this->getChromeImport(); - $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks'); + $chromeImport->setFilepath(__DIR__ . '/../fixtures/chrome-bookmarks'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -173,13 +136,13 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase $res = $chromeImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $chromeImport->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 1], $chromeImport->getSummary()); } public function testImportWithRedis() { $chromeImport = $this->getChromeImport(); - $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks'); + $chromeImport->setFilepath(__DIR__ . '/../fixtures/chrome-bookmarks'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -211,7 +174,7 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase $res = $chromeImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $chromeImport->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 1], $chromeImport->getSummary()); $this->assertNotEmpty($redisMock->lpop('chrome')); } @@ -219,7 +182,7 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase public function testImportBadFile() { $chromeImport = $this->getChromeImport(); - $chromeImport->setFilepath(__DIR__.'/../fixtures/wallabag-v1.jsonx'); + $chromeImport->setFilepath(__DIR__ . '/../fixtures/wallabag-v1.jsonx'); $res = $chromeImport->import(); @@ -227,13 +190,13 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase $records = $this->logHandler->getRecords(); $this->assertContains('Wallabag Browser Import: unable to read file', $records[0]['message']); - $this->assertEquals('ERROR', $records[0]['level_name']); + $this->assertSame('ERROR', $records[0]['level_name']); } public function testImportUserNotDefined() { $chromeImport = $this->getChromeImport(true); - $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks'); + $chromeImport->setFilepath(__DIR__ . '/../fixtures/chrome-bookmarks'); $res = $chromeImport->import(); @@ -241,6 +204,43 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase $records = $this->logHandler->getRecords(); $this->assertContains('Wallabag Browser Import: user is not defined', $records[0]['message']); - $this->assertEquals('ERROR', $records[0]['level_name']); + $this->assertSame('ERROR', $records[0]['level_name']); + } + + private function getChromeImport($unsetUser = false, $dispatched = 0) + { + $this->user = new User(); + + $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') + ->disableOriginalConstructor() + ->getMock(); + + $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') + ->disableOriginalConstructor() + ->getMock(); + + $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') + ->disableOriginalConstructor() + ->getMock(); + + $dispatcher + ->expects($this->exactly($dispatched)) + ->method('dispatch'); + + $wallabag = new ChromeImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher); + + $this->logHandler = new TestHandler(); + $logger = new Logger('test', [$this->logHandler]); + $wallabag->setLogger($logger); + + if (false === $unsetUser) { + $wallabag->setUser($this->user); + } + + return $wallabag; } } diff --git a/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php b/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php index c186c820..a1783bfc 100644 --- a/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php @@ -2,14 +2,14 @@ namespace Tests\Wallabag\ImportBundle\Import; -use Wallabag\ImportBundle\Import\FirefoxImport; -use Wallabag\UserBundle\Entity\User; -use Wallabag\CoreBundle\Entity\Entry; -use Wallabag\ImportBundle\Redis\Producer; -use Monolog\Logger; +use M6Web\Component\RedisMock\RedisMockFactory; use Monolog\Handler\TestHandler; +use Monolog\Logger; use Simpleue\Queue\RedisQueue; -use M6Web\Component\RedisMock\RedisMockFactory; +use Wallabag\CoreBundle\Entity\Entry; +use Wallabag\ImportBundle\Import\FirefoxImport; +use Wallabag\ImportBundle\Redis\Producer; +use Wallabag\UserBundle\Entity\User; class FirefoxImportTest extends \PHPUnit_Framework_TestCase { @@ -19,56 +19,19 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase protected $contentProxy; protected $tagsAssigner; - private function getFirefoxImport($unsetUser = false, $dispatched = 0) - { - $this->user = new User(); - - $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') - ->disableOriginalConstructor() - ->getMock(); - - $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') - ->disableOriginalConstructor() - ->getMock(); - - $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') - ->disableOriginalConstructor() - ->getMock(); - - $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') - ->disableOriginalConstructor() - ->getMock(); - - $dispatcher - ->expects($this->exactly($dispatched)) - ->method('dispatch'); - - $wallabag = new FirefoxImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher); - - $this->logHandler = new TestHandler(); - $logger = new Logger('test', [$this->logHandler]); - $wallabag->setLogger($logger); - - if (false === $unsetUser) { - $wallabag->setUser($this->user); - } - - return $wallabag; - } - public function testInit() { $firefoxImport = $this->getFirefoxImport(); - $this->assertEquals('Firefox', $firefoxImport->getName()); + $this->assertSame('Firefox', $firefoxImport->getName()); $this->assertNotEmpty($firefoxImport->getUrl()); - $this->assertEquals('import.firefox.description', $firefoxImport->getDescription()); + $this->assertSame('import.firefox.description', $firefoxImport->getDescription()); } public function testImport() { $firefoxImport = $this->getFirefoxImport(false, 2); - $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); + $firefoxImport->setFilepath(__DIR__ . '/../fixtures/firefox-bookmarks.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -95,13 +58,13 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase $res = $firefoxImport->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 2, 'queued' => 0], $firefoxImport->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 2, 'queued' => 0], $firefoxImport->getSummary()); } public function testImportAndMarkAllAsRead() { $firefoxImport = $this->getFirefoxImport(false, 1); - $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); + $firefoxImport->setFilepath(__DIR__ . '/../fixtures/firefox-bookmarks.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -133,13 +96,13 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase $this->assertTrue($res); - $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $firefoxImport->getSummary()); + $this->assertSame(['skipped' => 1, 'imported' => 1, 'queued' => 0], $firefoxImport->getSummary()); } public function testImportWithRabbit() { $firefoxImport = $this->getFirefoxImport(); - $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); + $firefoxImport->setFilepath(__DIR__ . '/../fixtures/firefox-bookmarks.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -173,13 +136,13 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase $res = $firefoxImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $firefoxImport->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 1], $firefoxImport->getSummary()); } public function testImportWithRedis() { $firefoxImport = $this->getFirefoxImport(); - $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); + $firefoxImport->setFilepath(__DIR__ . '/../fixtures/firefox-bookmarks.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -211,7 +174,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase $res = $firefoxImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $firefoxImport->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 1], $firefoxImport->getSummary()); $this->assertNotEmpty($redisMock->lpop('firefox')); } @@ -219,7 +182,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase public function testImportBadFile() { $firefoxImport = $this->getFirefoxImport(); - $firefoxImport->setFilepath(__DIR__.'/../fixtures/wallabag-v1.jsonx'); + $firefoxImport->setFilepath(__DIR__ . '/../fixtures/wallabag-v1.jsonx'); $res = $firefoxImport->import(); @@ -227,13 +190,13 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase $records = $this->logHandler->getRecords(); $this->assertContains('Wallabag Browser Import: unable to read file', $records[0]['message']); - $this->assertEquals('ERROR', $records[0]['level_name']); + $this->assertSame('ERROR', $records[0]['level_name']); } public function testImportUserNotDefined() { $firefoxImport = $this->getFirefoxImport(true); - $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); + $firefoxImport->setFilepath(__DIR__ . '/../fixtures/firefox-bookmarks.json'); $res = $firefoxImport->import(); @@ -241,6 +204,43 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase $records = $this->logHandler->getRecords(); $this->assertContains('Wallabag Browser Import: user is not defined', $records[0]['message']); - $this->assertEquals('ERROR', $records[0]['level_name']); + $this->assertSame('ERROR', $records[0]['level_name']); + } + + private function getFirefoxImport($unsetUser = false, $dispatched = 0) + { + $this->user = new User(); + + $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') + ->disableOriginalConstructor() + ->getMock(); + + $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') + ->disableOriginalConstructor() + ->getMock(); + + $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') + ->disableOriginalConstructor() + ->getMock(); + + $dispatcher + ->expects($this->exactly($dispatched)) + ->method('dispatch'); + + $wallabag = new FirefoxImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher); + + $this->logHandler = new TestHandler(); + $logger = new Logger('test', [$this->logHandler]); + $wallabag->setLogger($logger); + + if (false === $unsetUser) { + $wallabag->setUser($this->user); + } + + return $wallabag; } } diff --git a/tests/Wallabag/ImportBundle/Import/ImportChainTest.php b/tests/Wallabag/ImportBundle/Import/ImportChainTest.php index 32568ce5..a9a9915e 100644 --- a/tests/Wallabag/ImportBundle/Import/ImportChainTest.php +++ b/tests/Wallabag/ImportBundle/Import/ImportChainTest.php @@ -16,6 +16,6 @@ class ImportChainTest extends \PHPUnit_Framework_TestCase $importChain->addImport($import, 'alias'); $this->assertCount(1, $importChain->getAll()); - $this->assertEquals($import, $importChain->getAll()['alias']); + $this->assertSame($import, $importChain->getAll()['alias']); } } diff --git a/tests/Wallabag/ImportBundle/Import/ImportCompilerPassTest.php b/tests/Wallabag/ImportBundle/Import/ImportCompilerPassTest.php index 71a007a9..207054f4 100644 --- a/tests/Wallabag/ImportBundle/Import/ImportCompilerPassTest.php +++ b/tests/Wallabag/ImportBundle/Import/ImportCompilerPassTest.php @@ -36,7 +36,7 @@ class ImportCompilerPassTest extends \PHPUnit_Framework_TestCase $this->assertTrue($definition->hasMethodCall('addImport')); $calls = $definition->getMethodCalls(); - $this->assertEquals('pocket', $calls[0][1][1]); + $this->assertSame('pocket', $calls[0][1][1]); } protected function process(ContainerBuilder $container) diff --git a/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php b/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php index 9158c8a2..274dc326 100644 --- a/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php @@ -2,14 +2,14 @@ namespace Tests\Wallabag\ImportBundle\Import; -use Wallabag\ImportBundle\Import\InstapaperImport; -use Wallabag\UserBundle\Entity\User; -use Wallabag\CoreBundle\Entity\Entry; -use Wallabag\ImportBundle\Redis\Producer; -use Monolog\Logger; +use M6Web\Component\RedisMock\RedisMockFactory; use Monolog\Handler\TestHandler; +use Monolog\Logger; use Simpleue\Queue\RedisQueue; -use M6Web\Component\RedisMock\RedisMockFactory; +use Wallabag\CoreBundle\Entity\Entry; +use Wallabag\ImportBundle\Import\InstapaperImport; +use Wallabag\ImportBundle\Redis\Producer; +use Wallabag\UserBundle\Entity\User; class InstapaperImportTest extends \PHPUnit_Framework_TestCase { @@ -20,70 +20,19 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase protected $tagsAssigner; protected $uow; - private function getInstapaperImport($unsetUser = false, $dispatched = 0) - { - $this->user = new User(); - - $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') - ->disableOriginalConstructor() - ->getMock(); - - $this->uow = $this->getMockBuilder('Doctrine\ORM\UnitOfWork') - ->disableOriginalConstructor() - ->getMock(); - - $this->em - ->expects($this->any()) - ->method('getUnitOfWork') - ->willReturn($this->uow); - - $this->uow - ->expects($this->any()) - ->method('getScheduledEntityInsertions') - ->willReturn([]); - - $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') - ->disableOriginalConstructor() - ->getMock(); - - $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') - ->disableOriginalConstructor() - ->getMock(); - - $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') - ->disableOriginalConstructor() - ->getMock(); - - $dispatcher - ->expects($this->exactly($dispatched)) - ->method('dispatch'); - - $import = new InstapaperImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher); - - $this->logHandler = new TestHandler(); - $logger = new Logger('test', [$this->logHandler]); - $import->setLogger($logger); - - if (false === $unsetUser) { - $import->setUser($this->user); - } - - return $import; - } - public function testInit() { $instapaperImport = $this->getInstapaperImport(); - $this->assertEquals('Instapaper', $instapaperImport->getName()); + $this->assertSame('Instapaper', $instapaperImport->getName()); $this->assertNotEmpty($instapaperImport->getUrl()); - $this->assertEquals('import.instapaper.description', $instapaperImport->getDescription()); + $this->assertSame('import.instapaper.description', $instapaperImport->getDescription()); } public function testImport() { $instapaperImport = $this->getInstapaperImport(false, 4); - $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv'); + $instapaperImport->setFilepath(__DIR__ . '/../fixtures/instapaper-export.csv'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -110,13 +59,13 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase $res = $instapaperImport->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 4, 'queued' => 0], $instapaperImport->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 4, 'queued' => 0], $instapaperImport->getSummary()); } public function testImportAndMarkAllAsRead() { $instapaperImport = $this->getInstapaperImport(false, 1); - $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv'); + $instapaperImport->setFilepath(__DIR__ . '/../fixtures/instapaper-export.csv'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -148,13 +97,13 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase $this->assertTrue($res); - $this->assertEquals(['skipped' => 3, 'imported' => 1, 'queued' => 0], $instapaperImport->getSummary()); + $this->assertSame(['skipped' => 3, 'imported' => 1, 'queued' => 0], $instapaperImport->getSummary()); } public function testImportWithRabbit() { $instapaperImport = $this->getInstapaperImport(); - $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv'); + $instapaperImport->setFilepath(__DIR__ . '/../fixtures/instapaper-export.csv'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -188,13 +137,13 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase $res = $instapaperImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $instapaperImport->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 4], $instapaperImport->getSummary()); } public function testImportWithRedis() { $instapaperImport = $this->getInstapaperImport(); - $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv'); + $instapaperImport->setFilepath(__DIR__ . '/../fixtures/instapaper-export.csv'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -226,7 +175,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase $res = $instapaperImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $instapaperImport->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 4], $instapaperImport->getSummary()); $this->assertNotEmpty($redisMock->lpop('instapaper')); } @@ -234,7 +183,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase public function testImportBadFile() { $instapaperImport = $this->getInstapaperImport(); - $instapaperImport->setFilepath(__DIR__.'/../fixtures/wallabag-v1.jsonx'); + $instapaperImport->setFilepath(__DIR__ . '/../fixtures/wallabag-v1.jsonx'); $res = $instapaperImport->import(); @@ -242,13 +191,13 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase $records = $this->logHandler->getRecords(); $this->assertContains('InstapaperImport: unable to read file', $records[0]['message']); - $this->assertEquals('ERROR', $records[0]['level_name']); + $this->assertSame('ERROR', $records[0]['level_name']); } public function testImportUserNotDefined() { $instapaperImport = $this->getInstapaperImport(true); - $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv'); + $instapaperImport->setFilepath(__DIR__ . '/../fixtures/instapaper-export.csv'); $res = $instapaperImport->import(); @@ -256,6 +205,57 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase $records = $this->logHandler->getRecords(); $this->assertContains('InstapaperImport: user is not defined', $records[0]['message']); - $this->assertEquals('ERROR', $records[0]['level_name']); + $this->assertSame('ERROR', $records[0]['level_name']); + } + + private function getInstapaperImport($unsetUser = false, $dispatched = 0) + { + $this->user = new User(); + + $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $this->uow = $this->getMockBuilder('Doctrine\ORM\UnitOfWork') + ->disableOriginalConstructor() + ->getMock(); + + $this->em + ->expects($this->any()) + ->method('getUnitOfWork') + ->willReturn($this->uow); + + $this->uow + ->expects($this->any()) + ->method('getScheduledEntityInsertions') + ->willReturn([]); + + $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') + ->disableOriginalConstructor() + ->getMock(); + + $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') + ->disableOriginalConstructor() + ->getMock(); + + $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') + ->disableOriginalConstructor() + ->getMock(); + + $dispatcher + ->expects($this->exactly($dispatched)) + ->method('dispatch'); + + $import = new InstapaperImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher); + + $this->logHandler = new TestHandler(); + $logger = new Logger('test', [$this->logHandler]); + $import->setLogger($logger); + + if (false === $unsetUser) { + $import->setUser($this->user); + } + + return $import; } } diff --git a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php index b81ebe15..fe59f867 100644 --- a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php @@ -2,19 +2,19 @@ namespace Tests\Wallabag\ImportBundle\Import; -use Wallabag\UserBundle\Entity\User; -use Wallabag\CoreBundle\Entity\Entry; -use Wallabag\CoreBundle\Entity\Config; -use Wallabag\ImportBundle\Import\PocketImport; use GuzzleHttp\Client; -use GuzzleHttp\Subscriber\Mock; use GuzzleHttp\Message\Response; use GuzzleHttp\Stream\Stream; -use Wallabag\ImportBundle\Redis\Producer; -use Monolog\Logger; +use GuzzleHttp\Subscriber\Mock; +use M6Web\Component\RedisMock\RedisMockFactory; use Monolog\Handler\TestHandler; +use Monolog\Logger; use Simpleue\Queue\RedisQueue; -use M6Web\Component\RedisMock\RedisMockFactory; +use Wallabag\CoreBundle\Entity\Config; +use Wallabag\CoreBundle\Entity\Entry; +use Wallabag\ImportBundle\Import\PocketImport; +use Wallabag\ImportBundle\Redis\Producer; +use Wallabag\UserBundle\Entity\User; class PocketImportTest extends \PHPUnit_Framework_TestCase { @@ -26,66 +26,13 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase protected $tagsAssigner; protected $uow; - private function getPocketImport($consumerKey = 'ConsumerKey', $dispatched = 0) - { - $this->user = new User(); - - $config = new Config($this->user); - $config->setPocketConsumerKey('xxx'); - - $this->user->setConfig($config); - - $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') - ->disableOriginalConstructor() - ->getMock(); - - $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') - ->disableOriginalConstructor() - ->getMock(); - - $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') - ->disableOriginalConstructor() - ->getMock(); - - $this->uow = $this->getMockBuilder('Doctrine\ORM\UnitOfWork') - ->disableOriginalConstructor() - ->getMock(); - - $this->em - ->expects($this->any()) - ->method('getUnitOfWork') - ->willReturn($this->uow); - - $this->uow - ->expects($this->any()) - ->method('getScheduledEntityInsertions') - ->willReturn([]); - - $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') - ->disableOriginalConstructor() - ->getMock(); - - $dispatcher - ->expects($this->exactly($dispatched)) - ->method('dispatch'); - - $pocket = new PocketImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher); - $pocket->setUser($this->user); - - $this->logHandler = new TestHandler(); - $logger = new Logger('test', [$this->logHandler]); - $pocket->setLogger($logger); - - return $pocket; - } - public function testInit() { $pocketImport = $this->getPocketImport(); - $this->assertEquals('Pocket', $pocketImport->getName()); + $this->assertSame('Pocket', $pocketImport->getName()); $this->assertNotEmpty($pocketImport->getUrl()); - $this->assertEquals('import.pocket.description', $pocketImport->getDescription()); + $this->assertSame('import.pocket.description', $pocketImport->getDescription()); } public function testOAuthRequest() @@ -103,7 +50,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase $code = $pocketImport->getRequestToken('http://0.0.0.0/redirect'); - $this->assertEquals('wunderbar_code', $code); + $this->assertSame('wunderbar_code', $code); } public function testOAuthRequestBadResponse() @@ -125,7 +72,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase $records = $this->logHandler->getRecords(); $this->assertContains('PocketImport: Failed to request token', $records[0]['message']); - $this->assertEquals('ERROR', $records[0]['level_name']); + $this->assertSame('ERROR', $records[0]['level_name']); } public function testOAuthAuthorize() @@ -144,7 +91,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase $res = $pocketImport->authorize('wunderbar_code'); $this->assertTrue($res); - $this->assertEquals('wunderbar_token', $pocketImport->getAccessToken()); + $this->assertSame('wunderbar_token', $pocketImport->getAccessToken()); } public function testOAuthAuthorizeBadResponse() @@ -166,7 +113,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase $records = $this->logHandler->getRecords(); $this->assertContains('PocketImport: Failed to authorize client', $records[0]['message']); - $this->assertEquals('ERROR', $records[0]['level_name']); + $this->assertSame('ERROR', $records[0]['level_name']); } /** @@ -291,7 +238,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase $res = $pocketImport->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $pocketImport->getSummary()); + $this->assertSame(['skipped' => 1, 'imported' => 1, 'queued' => 0], $pocketImport->getSummary()); } /** @@ -386,7 +333,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase $res = $pocketImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 2, 'queued' => 0], $pocketImport->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 2, 'queued' => 0], $pocketImport->getSummary()); } /** @@ -425,7 +372,7 @@ JSON; { "status": 1, "list": { - "229279690": '.$body.' + "229279690": ' . $body . ' } } ')), @@ -472,7 +419,7 @@ JSON; $res = $pocketImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $pocketImport->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 1], $pocketImport->getSummary()); } /** @@ -511,7 +458,7 @@ JSON; { "status": 1, "list": { - "229279690": '.$body.' + "229279690": ' . $body . ' } } ')), @@ -551,7 +498,7 @@ JSON; $res = $pocketImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $pocketImport->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 1], $pocketImport->getSummary()); $this->assertNotEmpty($redisMock->lpop('pocket')); } @@ -577,7 +524,7 @@ JSON; $records = $this->logHandler->getRecords(); $this->assertContains('PocketImport: Failed to import', $records[0]['message']); - $this->assertEquals('ERROR', $records[0]['level_name']); + $this->assertSame('ERROR', $records[0]['level_name']); } public function testImportWithExceptionFromGraby() @@ -630,6 +577,59 @@ JSON; $res = $pocketImport->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 1, 'queued' => 0], $pocketImport->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 1, 'queued' => 0], $pocketImport->getSummary()); + } + + private function getPocketImport($consumerKey = 'ConsumerKey', $dispatched = 0) + { + $this->user = new User(); + + $config = new Config($this->user); + $config->setPocketConsumerKey('xxx'); + + $this->user->setConfig($config); + + $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') + ->disableOriginalConstructor() + ->getMock(); + + $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') + ->disableOriginalConstructor() + ->getMock(); + + $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $this->uow = $this->getMockBuilder('Doctrine\ORM\UnitOfWork') + ->disableOriginalConstructor() + ->getMock(); + + $this->em + ->expects($this->any()) + ->method('getUnitOfWork') + ->willReturn($this->uow); + + $this->uow + ->expects($this->any()) + ->method('getScheduledEntityInsertions') + ->willReturn([]); + + $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') + ->disableOriginalConstructor() + ->getMock(); + + $dispatcher + ->expects($this->exactly($dispatched)) + ->method('dispatch'); + + $pocket = new PocketImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher); + $pocket->setUser($this->user); + + $this->logHandler = new TestHandler(); + $logger = new Logger('test', [$this->logHandler]); + $pocket->setLogger($logger); + + return $pocket; } } diff --git a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php index 8f466d38..1822cdaa 100644 --- a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php @@ -2,14 +2,14 @@ namespace Tests\Wallabag\ImportBundle\Import; -use Wallabag\ImportBundle\Import\ReadabilityImport; -use Wallabag\UserBundle\Entity\User; -use Wallabag\CoreBundle\Entity\Entry; -use Wallabag\ImportBundle\Redis\Producer; -use Monolog\Logger; +use M6Web\Component\RedisMock\RedisMockFactory; use Monolog\Handler\TestHandler; +use Monolog\Logger; use Simpleue\Queue\RedisQueue; -use M6Web\Component\RedisMock\RedisMockFactory; +use Wallabag\CoreBundle\Entity\Entry; +use Wallabag\ImportBundle\Import\ReadabilityImport; +use Wallabag\ImportBundle\Redis\Producer; +use Wallabag\UserBundle\Entity\User; class ReadabilityImportTest extends \PHPUnit_Framework_TestCase { @@ -19,56 +19,19 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase protected $contentProxy; protected $tagsAssigner; - private function getReadabilityImport($unsetUser = false, $dispatched = 0) - { - $this->user = new User(); - - $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') - ->disableOriginalConstructor() - ->getMock(); - - $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') - ->disableOriginalConstructor() - ->getMock(); - - $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') - ->disableOriginalConstructor() - ->getMock(); - - $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') - ->disableOriginalConstructor() - ->getMock(); - - $dispatcher - ->expects($this->exactly($dispatched)) - ->method('dispatch'); - - $wallabag = new ReadabilityImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher); - - $this->logHandler = new TestHandler(); - $logger = new Logger('test', [$this->logHandler]); - $wallabag->setLogger($logger); - - if (false === $unsetUser) { - $wallabag->setUser($this->user); - } - - return $wallabag; - } - public function testInit() { $readabilityImport = $this->getReadabilityImport(); - $this->assertEquals('Readability', $readabilityImport->getName()); + $this->assertSame('Readability', $readabilityImport->getName()); $this->assertNotEmpty($readabilityImport->getUrl()); - $this->assertEquals('import.readability.description', $readabilityImport->getDescription()); + $this->assertSame('import.readability.description', $readabilityImport->getDescription()); } public function testImport() { $readabilityImport = $this->getReadabilityImport(false, 3); - $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability.json'); + $readabilityImport->setFilepath(__DIR__ . '/../fixtures/readability.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -95,13 +58,13 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $res = $readabilityImport->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 3, 'queued' => 0], $readabilityImport->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 3, 'queued' => 0], $readabilityImport->getSummary()); } public function testImportAndMarkAllAsRead() { $readabilityImport = $this->getReadabilityImport(false, 1); - $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability-read.json'); + $readabilityImport->setFilepath(__DIR__ . '/../fixtures/readability-read.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -133,13 +96,13 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $this->assertTrue($res); - $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $readabilityImport->getSummary()); + $this->assertSame(['skipped' => 1, 'imported' => 1, 'queued' => 0], $readabilityImport->getSummary()); } public function testImportWithRabbit() { $readabilityImport = $this->getReadabilityImport(); - $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability.json'); + $readabilityImport->setFilepath(__DIR__ . '/../fixtures/readability.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -173,13 +136,13 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $res = $readabilityImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 3], $readabilityImport->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 3], $readabilityImport->getSummary()); } public function testImportWithRedis() { $readabilityImport = $this->getReadabilityImport(); - $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability.json'); + $readabilityImport->setFilepath(__DIR__ . '/../fixtures/readability.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -211,7 +174,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $res = $readabilityImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 3], $readabilityImport->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 3], $readabilityImport->getSummary()); $this->assertNotEmpty($redisMock->lpop('readability')); } @@ -219,7 +182,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase public function testImportBadFile() { $readabilityImport = $this->getReadabilityImport(); - $readabilityImport->setFilepath(__DIR__.'/../fixtures/wallabag-v1.jsonx'); + $readabilityImport->setFilepath(__DIR__ . '/../fixtures/wallabag-v1.jsonx'); $res = $readabilityImport->import(); @@ -227,13 +190,13 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $records = $this->logHandler->getRecords(); $this->assertContains('ReadabilityImport: unable to read file', $records[0]['message']); - $this->assertEquals('ERROR', $records[0]['level_name']); + $this->assertSame('ERROR', $records[0]['level_name']); } public function testImportUserNotDefined() { $readabilityImport = $this->getReadabilityImport(true); - $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability.json'); + $readabilityImport->setFilepath(__DIR__ . '/../fixtures/readability.json'); $res = $readabilityImport->import(); @@ -241,6 +204,43 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $records = $this->logHandler->getRecords(); $this->assertContains('ReadabilityImport: user is not defined', $records[0]['message']); - $this->assertEquals('ERROR', $records[0]['level_name']); + $this->assertSame('ERROR', $records[0]['level_name']); + } + + private function getReadabilityImport($unsetUser = false, $dispatched = 0) + { + $this->user = new User(); + + $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') + ->disableOriginalConstructor() + ->getMock(); + + $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') + ->disableOriginalConstructor() + ->getMock(); + + $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') + ->disableOriginalConstructor() + ->getMock(); + + $dispatcher + ->expects($this->exactly($dispatched)) + ->method('dispatch'); + + $wallabag = new ReadabilityImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher); + + $this->logHandler = new TestHandler(); + $logger = new Logger('test', [$this->logHandler]); + $wallabag->setLogger($logger); + + if (false === $unsetUser) { + $wallabag->setUser($this->user); + } + + return $wallabag; } } diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php index 834b7ef5..822ad694 100644 --- a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php @@ -2,14 +2,14 @@ namespace Tests\Wallabag\ImportBundle\Import; -use Wallabag\ImportBundle\Import\WallabagV1Import; -use Wallabag\UserBundle\Entity\User; -use Wallabag\CoreBundle\Entity\Entry; -use Wallabag\ImportBundle\Redis\Producer; -use Monolog\Logger; +use M6Web\Component\RedisMock\RedisMockFactory; use Monolog\Handler\TestHandler; +use Monolog\Logger; use Simpleue\Queue\RedisQueue; -use M6Web\Component\RedisMock\RedisMockFactory; +use Wallabag\CoreBundle\Entity\Entry; +use Wallabag\ImportBundle\Import\WallabagV1Import; +use Wallabag\ImportBundle\Redis\Producer; +use Wallabag\UserBundle\Entity\User; class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase { @@ -22,77 +22,19 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase protected $fetchingErrorMessageTitle = 'No title found'; protected $fetchingErrorMessage = 'wallabag can\'t retrieve contents for this article. Please troubleshoot this issue.'; - private function getWallabagV1Import($unsetUser = false, $dispatched = 0) - { - $this->user = new User(); - - $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') - ->disableOriginalConstructor() - ->getMock(); - - $this->uow = $this->getMockBuilder('Doctrine\ORM\UnitOfWork') - ->disableOriginalConstructor() - ->getMock(); - - $this->em - ->expects($this->any()) - ->method('getUnitOfWork') - ->willReturn($this->uow); - - $this->uow - ->expects($this->any()) - ->method('getScheduledEntityInsertions') - ->willReturn([]); - - $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') - ->disableOriginalConstructor() - ->getMock(); - - $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') - ->disableOriginalConstructor() - ->getMock(); - - $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') - ->disableOriginalConstructor() - ->getMock(); - - $dispatcher - ->expects($this->exactly($dispatched)) - ->method('dispatch'); - - $wallabag = new WallabagV1Import( - $this->em, - $this->contentProxy, - $this->tagsAssigner, - $dispatcher, - $this->fetchingErrorMessageTitle, - $this->fetchingErrorMessage - ); - - $this->logHandler = new TestHandler(); - $logger = new Logger('test', [$this->logHandler]); - $wallabag->setLogger($logger); - - if (false === $unsetUser) { - $wallabag->setUser($this->user); - } - - return $wallabag; - } - public function testInit() { $wallabagV1Import = $this->getWallabagV1Import(); - $this->assertEquals('wallabag v1', $wallabagV1Import->getName()); + $this->assertSame('wallabag v1', $wallabagV1Import->getName()); $this->assertNotEmpty($wallabagV1Import->getUrl()); - $this->assertEquals('import.wallabag_v1.description', $wallabagV1Import->getDescription()); + $this->assertSame('import.wallabag_v1.description', $wallabagV1Import->getDescription()); } public function testImport() { $wallabagV1Import = $this->getWallabagV1Import(false, 1); - $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1.json'); + $wallabagV1Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v1.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -119,13 +61,13 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase $res = $wallabagV1Import->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $wallabagV1Import->getSummary()); + $this->assertSame(['skipped' => 1, 'imported' => 1, 'queued' => 0], $wallabagV1Import->getSummary()); } public function testImportAndMarkAllAsRead() { $wallabagV1Import = $this->getWallabagV1Import(false, 3); - $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1-read.json'); + $wallabagV1Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v1-read.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -157,13 +99,13 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 3, 'queued' => 0], $wallabagV1Import->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 3, 'queued' => 0], $wallabagV1Import->getSummary()); } public function testImportWithRabbit() { $wallabagV1Import = $this->getWallabagV1Import(); - $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1.json'); + $wallabagV1Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v1.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -197,13 +139,13 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase $res = $wallabagV1Import->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 2], $wallabagV1Import->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 2], $wallabagV1Import->getSummary()); } public function testImportWithRedis() { $wallabagV1Import = $this->getWallabagV1Import(); - $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1.json'); + $wallabagV1Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v1.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -235,7 +177,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase $res = $wallabagV1Import->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 2], $wallabagV1Import->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 2], $wallabagV1Import->getSummary()); $this->assertNotEmpty($redisMock->lpop('wallabag_v1')); } @@ -243,7 +185,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase public function testImportBadFile() { $wallabagV1Import = $this->getWallabagV1Import(); - $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1.jsonx'); + $wallabagV1Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v1.jsonx'); $res = $wallabagV1Import->import(); @@ -251,13 +193,13 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase $records = $this->logHandler->getRecords(); $this->assertContains('WallabagImport: unable to read file', $records[0]['message']); - $this->assertEquals('ERROR', $records[0]['level_name']); + $this->assertSame('ERROR', $records[0]['level_name']); } public function testImportUserNotDefined() { $wallabagV1Import = $this->getWallabagV1Import(true); - $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1.json'); + $wallabagV1Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v1.json'); $res = $wallabagV1Import->import(); @@ -265,6 +207,64 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase $records = $this->logHandler->getRecords(); $this->assertContains('WallabagImport: user is not defined', $records[0]['message']); - $this->assertEquals('ERROR', $records[0]['level_name']); + $this->assertSame('ERROR', $records[0]['level_name']); + } + + private function getWallabagV1Import($unsetUser = false, $dispatched = 0) + { + $this->user = new User(); + + $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $this->uow = $this->getMockBuilder('Doctrine\ORM\UnitOfWork') + ->disableOriginalConstructor() + ->getMock(); + + $this->em + ->expects($this->any()) + ->method('getUnitOfWork') + ->willReturn($this->uow); + + $this->uow + ->expects($this->any()) + ->method('getScheduledEntityInsertions') + ->willReturn([]); + + $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') + ->disableOriginalConstructor() + ->getMock(); + + $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') + ->disableOriginalConstructor() + ->getMock(); + + $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') + ->disableOriginalConstructor() + ->getMock(); + + $dispatcher + ->expects($this->exactly($dispatched)) + ->method('dispatch'); + + $wallabag = new WallabagV1Import( + $this->em, + $this->contentProxy, + $this->tagsAssigner, + $dispatcher, + $this->fetchingErrorMessageTitle, + $this->fetchingErrorMessage + ); + + $this->logHandler = new TestHandler(); + $logger = new Logger('test', [$this->logHandler]); + $wallabag->setLogger($logger); + + if (false === $unsetUser) { + $wallabag->setUser($this->user); + } + + return $wallabag; } } diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php index 5cc04aa5..fab50a45 100644 --- a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php @@ -2,14 +2,14 @@ namespace Tests\Wallabag\ImportBundle\Import; -use Wallabag\ImportBundle\Import\WallabagV2Import; -use Wallabag\UserBundle\Entity\User; -use Wallabag\CoreBundle\Entity\Entry; -use Wallabag\ImportBundle\Redis\Producer; -use Monolog\Logger; +use M6Web\Component\RedisMock\RedisMockFactory; use Monolog\Handler\TestHandler; +use Monolog\Logger; use Simpleue\Queue\RedisQueue; -use M6Web\Component\RedisMock\RedisMockFactory; +use Wallabag\CoreBundle\Entity\Entry; +use Wallabag\ImportBundle\Import\WallabagV2Import; +use Wallabag\ImportBundle\Redis\Producer; +use Wallabag\UserBundle\Entity\User; class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase { @@ -20,70 +20,19 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase protected $tagsAssigner; protected $uow; - private function getWallabagV2Import($unsetUser = false, $dispatched = 0) - { - $this->user = new User(); - - $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') - ->disableOriginalConstructor() - ->getMock(); - - $this->uow = $this->getMockBuilder('Doctrine\ORM\UnitOfWork') - ->disableOriginalConstructor() - ->getMock(); - - $this->em - ->expects($this->any()) - ->method('getUnitOfWork') - ->willReturn($this->uow); - - $this->uow - ->expects($this->any()) - ->method('getScheduledEntityInsertions') - ->willReturn([]); - - $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') - ->disableOriginalConstructor() - ->getMock(); - - $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') - ->disableOriginalConstructor() - ->getMock(); - - $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') - ->disableOriginalConstructor() - ->getMock(); - - $dispatcher - ->expects($this->exactly($dispatched)) - ->method('dispatch'); - - $wallabag = new WallabagV2Import($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher); - - $this->logHandler = new TestHandler(); - $logger = new Logger('test', [$this->logHandler]); - $wallabag->setLogger($logger); - - if (false === $unsetUser) { - $wallabag->setUser($this->user); - } - - return $wallabag; - } - public function testInit() { $wallabagV2Import = $this->getWallabagV2Import(); - $this->assertEquals('wallabag v2', $wallabagV2Import->getName()); + $this->assertSame('wallabag v2', $wallabagV2Import->getName()); $this->assertNotEmpty($wallabagV2Import->getUrl()); - $this->assertEquals('import.wallabag_v2.description', $wallabagV2Import->getDescription()); + $this->assertSame('import.wallabag_v2.description', $wallabagV2Import->getDescription()); } public function testImport() { $wallabagV2Import = $this->getWallabagV2Import(false, 2); - $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json'); + $wallabagV2Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v2.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -106,13 +55,13 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase $res = $wallabagV2Import->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 4, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary()); + $this->assertSame(['skipped' => 4, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary()); } public function testImportAndMarkAllAsRead() { $wallabagV2Import = $this->getWallabagV2Import(false, 2); - $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2-read.json'); + $wallabagV2Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v2-read.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -144,13 +93,13 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary()); } public function testImportWithRabbit() { $wallabagV2Import = $this->getWallabagV2Import(); - $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json'); + $wallabagV2Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v2.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -180,13 +129,13 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase $res = $wallabagV2Import->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 6], $wallabagV2Import->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 6], $wallabagV2Import->getSummary()); } public function testImportWithRedis() { $wallabagV2Import = $this->getWallabagV2Import(); - $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json'); + $wallabagV2Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v2.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -214,7 +163,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase $res = $wallabagV2Import->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 6], $wallabagV2Import->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 6], $wallabagV2Import->getSummary()); $this->assertNotEmpty($redisMock->lpop('wallabag_v2')); } @@ -222,7 +171,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase public function testImportBadFile() { $wallabagV1Import = $this->getWallabagV2Import(); - $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.jsonx'); + $wallabagV1Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v2.jsonx'); $res = $wallabagV1Import->import(); @@ -230,13 +179,13 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase $records = $this->logHandler->getRecords(); $this->assertContains('WallabagImport: unable to read file', $records[0]['message']); - $this->assertEquals('ERROR', $records[0]['level_name']); + $this->assertSame('ERROR', $records[0]['level_name']); } public function testImportUserNotDefined() { $wallabagV1Import = $this->getWallabagV2Import(true); - $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json'); + $wallabagV1Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v2.json'); $res = $wallabagV1Import->import(); @@ -244,24 +193,24 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase $records = $this->logHandler->getRecords(); $this->assertContains('WallabagImport: user is not defined', $records[0]['message']); - $this->assertEquals('ERROR', $records[0]['level_name']); + $this->assertSame('ERROR', $records[0]['level_name']); } public function testImportEmptyFile() { $wallabagV2Import = $this->getWallabagV2Import(); - $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2-empty.json'); + $wallabagV2Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v2-empty.json'); $res = $wallabagV2Import->import(); $this->assertFalse($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 0], $wallabagV2Import->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 0], $wallabagV2Import->getSummary()); } public function testImportWithExceptionFromGraby() { $wallabagV2Import = $this->getWallabagV2Import(false, 2); - $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json'); + $wallabagV2Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v2.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -284,6 +233,57 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase $res = $wallabagV2Import->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 4, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary()); + $this->assertSame(['skipped' => 4, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary()); + } + + private function getWallabagV2Import($unsetUser = false, $dispatched = 0) + { + $this->user = new User(); + + $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $this->uow = $this->getMockBuilder('Doctrine\ORM\UnitOfWork') + ->disableOriginalConstructor() + ->getMock(); + + $this->em + ->expects($this->any()) + ->method('getUnitOfWork') + ->willReturn($this->uow); + + $this->uow + ->expects($this->any()) + ->method('getScheduledEntityInsertions') + ->willReturn([]); + + $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') + ->disableOriginalConstructor() + ->getMock(); + + $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') + ->disableOriginalConstructor() + ->getMock(); + + $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') + ->disableOriginalConstructor() + ->getMock(); + + $dispatcher + ->expects($this->exactly($dispatched)) + ->method('dispatch'); + + $wallabag = new WallabagV2Import($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher); + + $this->logHandler = new TestHandler(); + $logger = new Logger('test', [$this->logHandler]); + $wallabag->setLogger($logger); + + if (false === $unsetUser) { + $wallabag->setUser($this->user); + } + + return $wallabag; } } -- cgit v1.2.3