diff options
author | Jeremy Benoist <jeremy.benoist@gmail.com> | 2017-07-01 09:52:38 +0200 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2017-07-01 09:52:38 +0200 |
commit | f808b01692a835673f328d7221ba8c212caa9b61 (patch) | |
tree | 0c3b1fc5b1ddbd7af72227303503177689e1d403 /tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php | |
parent | 822c877949aff8ae57677671115f8f4fc69588d5 (diff) | |
download | wallabag-f808b01692a835673f328d7221ba8c212caa9b61.tar.gz wallabag-f808b01692a835673f328d7221ba8c212caa9b61.tar.zst wallabag-f808b01692a835673f328d7221ba8c212caa9b61.zip |
Add a real configuration for CS-Fixer
Diffstat (limited to 'tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php')
-rw-r--r-- | tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php | 114 |
1 files changed, 57 insertions, 57 deletions
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 @@ | |||
2 | 2 | ||
3 | namespace Tests\Wallabag\ImportBundle\Import; | 3 | namespace Tests\Wallabag\ImportBundle\Import; |
4 | 4 | ||
5 | use Wallabag\ImportBundle\Import\FirefoxImport; | 5 | use M6Web\Component\RedisMock\RedisMockFactory; |
6 | use Wallabag\UserBundle\Entity\User; | ||
7 | use Wallabag\CoreBundle\Entity\Entry; | ||
8 | use Wallabag\ImportBundle\Redis\Producer; | ||
9 | use Monolog\Logger; | ||
10 | use Monolog\Handler\TestHandler; | 6 | use Monolog\Handler\TestHandler; |
7 | use Monolog\Logger; | ||
11 | use Simpleue\Queue\RedisQueue; | 8 | use Simpleue\Queue\RedisQueue; |
12 | use M6Web\Component\RedisMock\RedisMockFactory; | 9 | use Wallabag\CoreBundle\Entity\Entry; |
10 | use Wallabag\ImportBundle\Import\FirefoxImport; | ||
11 | use Wallabag\ImportBundle\Redis\Producer; | ||
12 | use Wallabag\UserBundle\Entity\User; | ||
13 | 13 | ||
14 | class FirefoxImportTest extends \PHPUnit_Framework_TestCase | 14 | class FirefoxImportTest extends \PHPUnit_Framework_TestCase |
15 | { | 15 | { |
@@ -19,56 +19,19 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase | |||
19 | protected $contentProxy; | 19 | protected $contentProxy; |
20 | protected $tagsAssigner; | 20 | protected $tagsAssigner; |
21 | 21 | ||
22 | private function getFirefoxImport($unsetUser = false, $dispatched = 0) | ||
23 | { | ||
24 | $this->user = new User(); | ||
25 | |||
26 | $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') | ||
27 | ->disableOriginalConstructor() | ||
28 | ->getMock(); | ||
29 | |||
30 | $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') | ||
31 | ->disableOriginalConstructor() | ||
32 | ->getMock(); | ||
33 | |||
34 | $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') | ||
35 | ->disableOriginalConstructor() | ||
36 | ->getMock(); | ||
37 | |||
38 | $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') | ||
39 | ->disableOriginalConstructor() | ||
40 | ->getMock(); | ||
41 | |||
42 | $dispatcher | ||
43 | ->expects($this->exactly($dispatched)) | ||
44 | ->method('dispatch'); | ||
45 | |||
46 | $wallabag = new FirefoxImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher); | ||
47 | |||
48 | $this->logHandler = new TestHandler(); | ||
49 | $logger = new Logger('test', [$this->logHandler]); | ||
50 | $wallabag->setLogger($logger); | ||
51 | |||
52 | if (false === $unsetUser) { | ||
53 | $wallabag->setUser($this->user); | ||
54 | } | ||
55 | |||
56 | return $wallabag; | ||
57 | } | ||
58 | |||
59 | public function testInit() | 22 | public function testInit() |
60 | { | 23 | { |
61 | $firefoxImport = $this->getFirefoxImport(); | 24 | $firefoxImport = $this->getFirefoxImport(); |
62 | 25 | ||
63 | $this->assertEquals('Firefox', $firefoxImport->getName()); | 26 | $this->assertSame('Firefox', $firefoxImport->getName()); |
64 | $this->assertNotEmpty($firefoxImport->getUrl()); | 27 | $this->assertNotEmpty($firefoxImport->getUrl()); |
65 | $this->assertEquals('import.firefox.description', $firefoxImport->getDescription()); | 28 | $this->assertSame('import.firefox.description', $firefoxImport->getDescription()); |
66 | } | 29 | } |
67 | 30 | ||
68 | public function testImport() | 31 | public function testImport() |
69 | { | 32 | { |
70 | $firefoxImport = $this->getFirefoxImport(false, 2); | 33 | $firefoxImport = $this->getFirefoxImport(false, 2); |
71 | $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); | 34 | $firefoxImport->setFilepath(__DIR__ . '/../fixtures/firefox-bookmarks.json'); |
72 | 35 | ||
73 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') | 36 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') |
74 | ->disableOriginalConstructor() | 37 | ->disableOriginalConstructor() |
@@ -95,13 +58,13 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase | |||
95 | $res = $firefoxImport->import(); | 58 | $res = $firefoxImport->import(); |
96 | 59 | ||
97 | $this->assertTrue($res); | 60 | $this->assertTrue($res); |
98 | $this->assertEquals(['skipped' => 0, 'imported' => 2, 'queued' => 0], $firefoxImport->getSummary()); | 61 | $this->assertSame(['skipped' => 0, 'imported' => 2, 'queued' => 0], $firefoxImport->getSummary()); |
99 | } | 62 | } |
100 | 63 | ||
101 | public function testImportAndMarkAllAsRead() | 64 | public function testImportAndMarkAllAsRead() |
102 | { | 65 | { |
103 | $firefoxImport = $this->getFirefoxImport(false, 1); | 66 | $firefoxImport = $this->getFirefoxImport(false, 1); |
104 | $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); | 67 | $firefoxImport->setFilepath(__DIR__ . '/../fixtures/firefox-bookmarks.json'); |
105 | 68 | ||
106 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') | 69 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') |
107 | ->disableOriginalConstructor() | 70 | ->disableOriginalConstructor() |
@@ -133,13 +96,13 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase | |||
133 | 96 | ||
134 | $this->assertTrue($res); | 97 | $this->assertTrue($res); |
135 | 98 | ||
136 | $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $firefoxImport->getSummary()); | 99 | $this->assertSame(['skipped' => 1, 'imported' => 1, 'queued' => 0], $firefoxImport->getSummary()); |
137 | } | 100 | } |
138 | 101 | ||
139 | public function testImportWithRabbit() | 102 | public function testImportWithRabbit() |
140 | { | 103 | { |
141 | $firefoxImport = $this->getFirefoxImport(); | 104 | $firefoxImport = $this->getFirefoxImport(); |
142 | $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); | 105 | $firefoxImport->setFilepath(__DIR__ . '/../fixtures/firefox-bookmarks.json'); |
143 | 106 | ||
144 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') | 107 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') |
145 | ->disableOriginalConstructor() | 108 | ->disableOriginalConstructor() |
@@ -173,13 +136,13 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase | |||
173 | $res = $firefoxImport->setMarkAsRead(true)->import(); | 136 | $res = $firefoxImport->setMarkAsRead(true)->import(); |
174 | 137 | ||
175 | $this->assertTrue($res); | 138 | $this->assertTrue($res); |
176 | $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $firefoxImport->getSummary()); | 139 | $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 1], $firefoxImport->getSummary()); |
177 | } | 140 | } |
178 | 141 | ||
179 | public function testImportWithRedis() | 142 | public function testImportWithRedis() |
180 | { | 143 | { |
181 | $firefoxImport = $this->getFirefoxImport(); | 144 | $firefoxImport = $this->getFirefoxImport(); |
182 | $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); | 145 | $firefoxImport->setFilepath(__DIR__ . '/../fixtures/firefox-bookmarks.json'); |
183 | 146 | ||
184 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') | 147 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') |
185 | ->disableOriginalConstructor() | 148 | ->disableOriginalConstructor() |
@@ -211,7 +174,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase | |||
211 | $res = $firefoxImport->setMarkAsRead(true)->import(); | 174 | $res = $firefoxImport->setMarkAsRead(true)->import(); |
212 | 175 | ||
213 | $this->assertTrue($res); | 176 | $this->assertTrue($res); |
214 | $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $firefoxImport->getSummary()); | 177 | $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 1], $firefoxImport->getSummary()); |
215 | 178 | ||
216 | $this->assertNotEmpty($redisMock->lpop('firefox')); | 179 | $this->assertNotEmpty($redisMock->lpop('firefox')); |
217 | } | 180 | } |
@@ -219,7 +182,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase | |||
219 | public function testImportBadFile() | 182 | public function testImportBadFile() |
220 | { | 183 | { |
221 | $firefoxImport = $this->getFirefoxImport(); | 184 | $firefoxImport = $this->getFirefoxImport(); |
222 | $firefoxImport->setFilepath(__DIR__.'/../fixtures/wallabag-v1.jsonx'); | 185 | $firefoxImport->setFilepath(__DIR__ . '/../fixtures/wallabag-v1.jsonx'); |
223 | 186 | ||
224 | $res = $firefoxImport->import(); | 187 | $res = $firefoxImport->import(); |
225 | 188 | ||
@@ -227,13 +190,13 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase | |||
227 | 190 | ||
228 | $records = $this->logHandler->getRecords(); | 191 | $records = $this->logHandler->getRecords(); |
229 | $this->assertContains('Wallabag Browser Import: unable to read file', $records[0]['message']); | 192 | $this->assertContains('Wallabag Browser Import: unable to read file', $records[0]['message']); |
230 | $this->assertEquals('ERROR', $records[0]['level_name']); | 193 | $this->assertSame('ERROR', $records[0]['level_name']); |
231 | } | 194 | } |
232 | 195 | ||
233 | public function testImportUserNotDefined() | 196 | public function testImportUserNotDefined() |
234 | { | 197 | { |
235 | $firefoxImport = $this->getFirefoxImport(true); | 198 | $firefoxImport = $this->getFirefoxImport(true); |
236 | $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); | 199 | $firefoxImport->setFilepath(__DIR__ . '/../fixtures/firefox-bookmarks.json'); |
237 | 200 | ||
238 | $res = $firefoxImport->import(); | 201 | $res = $firefoxImport->import(); |
239 | 202 | ||
@@ -241,6 +204,43 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase | |||
241 | 204 | ||
242 | $records = $this->logHandler->getRecords(); | 205 | $records = $this->logHandler->getRecords(); |
243 | $this->assertContains('Wallabag Browser Import: user is not defined', $records[0]['message']); | 206 | $this->assertContains('Wallabag Browser Import: user is not defined', $records[0]['message']); |
244 | $this->assertEquals('ERROR', $records[0]['level_name']); | 207 | $this->assertSame('ERROR', $records[0]['level_name']); |
208 | } | ||
209 | |||
210 | private function getFirefoxImport($unsetUser = false, $dispatched = 0) | ||
211 | { | ||
212 | $this->user = new User(); | ||
213 | |||
214 | $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') | ||
215 | ->disableOriginalConstructor() | ||
216 | ->getMock(); | ||
217 | |||
218 | $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') | ||
219 | ->disableOriginalConstructor() | ||
220 | ->getMock(); | ||
221 | |||
222 | $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') | ||
223 | ->disableOriginalConstructor() | ||
224 | ->getMock(); | ||
225 | |||
226 | $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') | ||
227 | ->disableOriginalConstructor() | ||
228 | ->getMock(); | ||
229 | |||
230 | $dispatcher | ||
231 | ->expects($this->exactly($dispatched)) | ||
232 | ->method('dispatch'); | ||
233 | |||
234 | $wallabag = new FirefoxImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher); | ||
235 | |||
236 | $this->logHandler = new TestHandler(); | ||
237 | $logger = new Logger('test', [$this->logHandler]); | ||
238 | $wallabag->setLogger($logger); | ||
239 | |||
240 | if (false === $unsetUser) { | ||
241 | $wallabag->setUser($this->user); | ||
242 | } | ||
243 | |||
244 | return $wallabag; | ||
245 | } | 245 | } |
246 | } | 246 | } |