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/InstapaperImportTest.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/InstapaperImportTest.php')
-rw-r--r-- | tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php | 142 |
1 files changed, 71 insertions, 71 deletions
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 @@ | |||
2 | 2 | ||
3 | namespace Tests\Wallabag\ImportBundle\Import; | 3 | namespace Tests\Wallabag\ImportBundle\Import; |
4 | 4 | ||
5 | use Wallabag\ImportBundle\Import\InstapaperImport; | 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\InstapaperImport; | ||
11 | use Wallabag\ImportBundle\Redis\Producer; | ||
12 | use Wallabag\UserBundle\Entity\User; | ||
13 | 13 | ||
14 | class InstapaperImportTest extends \PHPUnit_Framework_TestCase | 14 | class InstapaperImportTest extends \PHPUnit_Framework_TestCase |
15 | { | 15 | { |
@@ -20,70 +20,19 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase | |||
20 | protected $tagsAssigner; | 20 | protected $tagsAssigner; |
21 | protected $uow; | 21 | protected $uow; |
22 | 22 | ||
23 | private function getInstapaperImport($unsetUser = false, $dispatched = 0) | ||
24 | { | ||
25 | $this->user = new User(); | ||
26 | |||
27 | $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') | ||
28 | ->disableOriginalConstructor() | ||
29 | ->getMock(); | ||
30 | |||
31 | $this->uow = $this->getMockBuilder('Doctrine\ORM\UnitOfWork') | ||
32 | ->disableOriginalConstructor() | ||
33 | ->getMock(); | ||
34 | |||
35 | $this->em | ||
36 | ->expects($this->any()) | ||
37 | ->method('getUnitOfWork') | ||
38 | ->willReturn($this->uow); | ||
39 | |||
40 | $this->uow | ||
41 | ->expects($this->any()) | ||
42 | ->method('getScheduledEntityInsertions') | ||
43 | ->willReturn([]); | ||
44 | |||
45 | $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') | ||
46 | ->disableOriginalConstructor() | ||
47 | ->getMock(); | ||
48 | |||
49 | $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') | ||
50 | ->disableOriginalConstructor() | ||
51 | ->getMock(); | ||
52 | |||
53 | $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') | ||
54 | ->disableOriginalConstructor() | ||
55 | ->getMock(); | ||
56 | |||
57 | $dispatcher | ||
58 | ->expects($this->exactly($dispatched)) | ||
59 | ->method('dispatch'); | ||
60 | |||
61 | $import = new InstapaperImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher); | ||
62 | |||
63 | $this->logHandler = new TestHandler(); | ||
64 | $logger = new Logger('test', [$this->logHandler]); | ||
65 | $import->setLogger($logger); | ||
66 | |||
67 | if (false === $unsetUser) { | ||
68 | $import->setUser($this->user); | ||
69 | } | ||
70 | |||
71 | return $import; | ||
72 | } | ||
73 | |||
74 | public function testInit() | 23 | public function testInit() |
75 | { | 24 | { |
76 | $instapaperImport = $this->getInstapaperImport(); | 25 | $instapaperImport = $this->getInstapaperImport(); |
77 | 26 | ||
78 | $this->assertEquals('Instapaper', $instapaperImport->getName()); | 27 | $this->assertSame('Instapaper', $instapaperImport->getName()); |
79 | $this->assertNotEmpty($instapaperImport->getUrl()); | 28 | $this->assertNotEmpty($instapaperImport->getUrl()); |
80 | $this->assertEquals('import.instapaper.description', $instapaperImport->getDescription()); | 29 | $this->assertSame('import.instapaper.description', $instapaperImport->getDescription()); |
81 | } | 30 | } |
82 | 31 | ||
83 | public function testImport() | 32 | public function testImport() |
84 | { | 33 | { |
85 | $instapaperImport = $this->getInstapaperImport(false, 4); | 34 | $instapaperImport = $this->getInstapaperImport(false, 4); |
86 | $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv'); | 35 | $instapaperImport->setFilepath(__DIR__ . '/../fixtures/instapaper-export.csv'); |
87 | 36 | ||
88 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') | 37 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') |
89 | ->disableOriginalConstructor() | 38 | ->disableOriginalConstructor() |
@@ -110,13 +59,13 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase | |||
110 | $res = $instapaperImport->import(); | 59 | $res = $instapaperImport->import(); |
111 | 60 | ||
112 | $this->assertTrue($res); | 61 | $this->assertTrue($res); |
113 | $this->assertEquals(['skipped' => 0, 'imported' => 4, 'queued' => 0], $instapaperImport->getSummary()); | 62 | $this->assertSame(['skipped' => 0, 'imported' => 4, 'queued' => 0], $instapaperImport->getSummary()); |
114 | } | 63 | } |
115 | 64 | ||
116 | public function testImportAndMarkAllAsRead() | 65 | public function testImportAndMarkAllAsRead() |
117 | { | 66 | { |
118 | $instapaperImport = $this->getInstapaperImport(false, 1); | 67 | $instapaperImport = $this->getInstapaperImport(false, 1); |
119 | $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv'); | 68 | $instapaperImport->setFilepath(__DIR__ . '/../fixtures/instapaper-export.csv'); |
120 | 69 | ||
121 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') | 70 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') |
122 | ->disableOriginalConstructor() | 71 | ->disableOriginalConstructor() |
@@ -148,13 +97,13 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase | |||
148 | 97 | ||
149 | $this->assertTrue($res); | 98 | $this->assertTrue($res); |
150 | 99 | ||
151 | $this->assertEquals(['skipped' => 3, 'imported' => 1, 'queued' => 0], $instapaperImport->getSummary()); | 100 | $this->assertSame(['skipped' => 3, 'imported' => 1, 'queued' => 0], $instapaperImport->getSummary()); |
152 | } | 101 | } |
153 | 102 | ||
154 | public function testImportWithRabbit() | 103 | public function testImportWithRabbit() |
155 | { | 104 | { |
156 | $instapaperImport = $this->getInstapaperImport(); | 105 | $instapaperImport = $this->getInstapaperImport(); |
157 | $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv'); | 106 | $instapaperImport->setFilepath(__DIR__ . '/../fixtures/instapaper-export.csv'); |
158 | 107 | ||
159 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') | 108 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') |
160 | ->disableOriginalConstructor() | 109 | ->disableOriginalConstructor() |
@@ -188,13 +137,13 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase | |||
188 | $res = $instapaperImport->setMarkAsRead(true)->import(); | 137 | $res = $instapaperImport->setMarkAsRead(true)->import(); |
189 | 138 | ||
190 | $this->assertTrue($res); | 139 | $this->assertTrue($res); |
191 | $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $instapaperImport->getSummary()); | 140 | $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 4], $instapaperImport->getSummary()); |
192 | } | 141 | } |
193 | 142 | ||
194 | public function testImportWithRedis() | 143 | public function testImportWithRedis() |
195 | { | 144 | { |
196 | $instapaperImport = $this->getInstapaperImport(); | 145 | $instapaperImport = $this->getInstapaperImport(); |
197 | $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv'); | 146 | $instapaperImport->setFilepath(__DIR__ . '/../fixtures/instapaper-export.csv'); |
198 | 147 | ||
199 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') | 148 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') |
200 | ->disableOriginalConstructor() | 149 | ->disableOriginalConstructor() |
@@ -226,7 +175,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase | |||
226 | $res = $instapaperImport->setMarkAsRead(true)->import(); | 175 | $res = $instapaperImport->setMarkAsRead(true)->import(); |
227 | 176 | ||
228 | $this->assertTrue($res); | 177 | $this->assertTrue($res); |
229 | $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $instapaperImport->getSummary()); | 178 | $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 4], $instapaperImport->getSummary()); |
230 | 179 | ||
231 | $this->assertNotEmpty($redisMock->lpop('instapaper')); | 180 | $this->assertNotEmpty($redisMock->lpop('instapaper')); |
232 | } | 181 | } |
@@ -234,7 +183,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase | |||
234 | public function testImportBadFile() | 183 | public function testImportBadFile() |
235 | { | 184 | { |
236 | $instapaperImport = $this->getInstapaperImport(); | 185 | $instapaperImport = $this->getInstapaperImport(); |
237 | $instapaperImport->setFilepath(__DIR__.'/../fixtures/wallabag-v1.jsonx'); | 186 | $instapaperImport->setFilepath(__DIR__ . '/../fixtures/wallabag-v1.jsonx'); |
238 | 187 | ||
239 | $res = $instapaperImport->import(); | 188 | $res = $instapaperImport->import(); |
240 | 189 | ||
@@ -242,13 +191,13 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase | |||
242 | 191 | ||
243 | $records = $this->logHandler->getRecords(); | 192 | $records = $this->logHandler->getRecords(); |
244 | $this->assertContains('InstapaperImport: unable to read file', $records[0]['message']); | 193 | $this->assertContains('InstapaperImport: unable to read file', $records[0]['message']); |
245 | $this->assertEquals('ERROR', $records[0]['level_name']); | 194 | $this->assertSame('ERROR', $records[0]['level_name']); |
246 | } | 195 | } |
247 | 196 | ||
248 | public function testImportUserNotDefined() | 197 | public function testImportUserNotDefined() |
249 | { | 198 | { |
250 | $instapaperImport = $this->getInstapaperImport(true); | 199 | $instapaperImport = $this->getInstapaperImport(true); |
251 | $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv'); | 200 | $instapaperImport->setFilepath(__DIR__ . '/../fixtures/instapaper-export.csv'); |
252 | 201 | ||
253 | $res = $instapaperImport->import(); | 202 | $res = $instapaperImport->import(); |
254 | 203 | ||
@@ -256,6 +205,57 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase | |||
256 | 205 | ||
257 | $records = $this->logHandler->getRecords(); | 206 | $records = $this->logHandler->getRecords(); |
258 | $this->assertContains('InstapaperImport: user is not defined', $records[0]['message']); | 207 | $this->assertContains('InstapaperImport: user is not defined', $records[0]['message']); |
259 | $this->assertEquals('ERROR', $records[0]['level_name']); | 208 | $this->assertSame('ERROR', $records[0]['level_name']); |
209 | } | ||
210 | |||
211 | private function getInstapaperImport($unsetUser = false, $dispatched = 0) | ||
212 | { | ||
213 | $this->user = new User(); | ||
214 | |||
215 | $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') | ||
216 | ->disableOriginalConstructor() | ||
217 | ->getMock(); | ||
218 | |||
219 | $this->uow = $this->getMockBuilder('Doctrine\ORM\UnitOfWork') | ||
220 | ->disableOriginalConstructor() | ||
221 | ->getMock(); | ||
222 | |||
223 | $this->em | ||
224 | ->expects($this->any()) | ||
225 | ->method('getUnitOfWork') | ||
226 | ->willReturn($this->uow); | ||
227 | |||
228 | $this->uow | ||
229 | ->expects($this->any()) | ||
230 | ->method('getScheduledEntityInsertions') | ||
231 | ->willReturn([]); | ||
232 | |||
233 | $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') | ||
234 | ->disableOriginalConstructor() | ||
235 | ->getMock(); | ||
236 | |||
237 | $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') | ||
238 | ->disableOriginalConstructor() | ||
239 | ->getMock(); | ||
240 | |||
241 | $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') | ||
242 | ->disableOriginalConstructor() | ||
243 | ->getMock(); | ||
244 | |||
245 | $dispatcher | ||
246 | ->expects($this->exactly($dispatched)) | ||
247 | ->method('dispatch'); | ||
248 | |||
249 | $import = new InstapaperImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher); | ||
250 | |||
251 | $this->logHandler = new TestHandler(); | ||
252 | $logger = new Logger('test', [$this->logHandler]); | ||
253 | $import->setLogger($logger); | ||
254 | |||
255 | if (false === $unsetUser) { | ||
256 | $import->setUser($this->user); | ||
257 | } | ||
258 | |||
259 | return $import; | ||
260 | } | 260 | } |
261 | } | 261 | } |