diff options
author | Jeremy Benoist <j0k3r@users.noreply.github.com> | 2016-09-19 07:15:40 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-19 07:15:40 +0200 |
commit | da18a4682f124b02278860d23ac1d59dee995277 (patch) | |
tree | eabbe9da7203eea41e0cb0ec3c26b9b6599cf58f /tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php | |
parent | 0ed8ce55b5caf2c88e8330afa83abef6c4aac9a4 (diff) | |
parent | 59b97fae996d8307b9d957d210d46200f6d206bf (diff) | |
download | wallabag-da18a4682f124b02278860d23ac1d59dee995277.tar.gz wallabag-da18a4682f124b02278860d23ac1d59dee995277.tar.zst wallabag-da18a4682f124b02278860d23ac1d59dee995277.zip |
Merge pull request #1941 from wallabag/v2-asynchronous-jobs
Use asynchronous jobs for imports
Diffstat (limited to 'tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php')
-rw-r--r-- | tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php | 83 |
1 files changed, 79 insertions, 4 deletions
diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php index 4a45e0f0..12bd6bdd 100644 --- a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php | |||
@@ -5,8 +5,11 @@ namespace Tests\Wallabag\ImportBundle\Import; | |||
5 | use Wallabag\ImportBundle\Import\WallabagV2Import; | 5 | use Wallabag\ImportBundle\Import\WallabagV2Import; |
6 | use Wallabag\UserBundle\Entity\User; | 6 | use Wallabag\UserBundle\Entity\User; |
7 | use Wallabag\CoreBundle\Entity\Entry; | 7 | use Wallabag\CoreBundle\Entity\Entry; |
8 | use Wallabag\ImportBundle\Redis\Producer; | ||
8 | use Monolog\Logger; | 9 | use Monolog\Logger; |
9 | use Monolog\Handler\TestHandler; | 10 | use Monolog\Handler\TestHandler; |
11 | use Simpleue\Queue\RedisQueue; | ||
12 | use M6Web\Component\RedisMock\RedisMockFactory; | ||
10 | 13 | ||
11 | class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase | 14 | class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase |
12 | { | 15 | { |
@@ -75,7 +78,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase | |||
75 | $res = $wallabagV2Import->import(); | 78 | $res = $wallabagV2Import->import(); |
76 | 79 | ||
77 | $this->assertTrue($res); | 80 | $this->assertTrue($res); |
78 | $this->assertEquals(['skipped' => 22, 'imported' => 2], $wallabagV2Import->getSummary()); | 81 | $this->assertEquals(['skipped' => 22, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary()); |
79 | } | 82 | } |
80 | 83 | ||
81 | public function testImportAndMarkAllAsRead() | 84 | public function testImportAndMarkAllAsRead() |
@@ -113,7 +116,79 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase | |||
113 | 116 | ||
114 | $this->assertTrue($res); | 117 | $this->assertTrue($res); |
115 | 118 | ||
116 | $this->assertEquals(['skipped' => 0, 'imported' => 2], $wallabagV2Import->getSummary()); | 119 | $this->assertEquals(['skipped' => 0, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary()); |
120 | } | ||
121 | |||
122 | public function testImportWithRabbit() | ||
123 | { | ||
124 | $wallabagV2Import = $this->getWallabagV2Import(); | ||
125 | $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json'); | ||
126 | |||
127 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') | ||
128 | ->disableOriginalConstructor() | ||
129 | ->getMock(); | ||
130 | |||
131 | $entryRepo->expects($this->never()) | ||
132 | ->method('findByUrlAndUserId'); | ||
133 | |||
134 | $this->em | ||
135 | ->expects($this->never()) | ||
136 | ->method('getRepository'); | ||
137 | |||
138 | $this->contentProxy | ||
139 | ->expects($this->never()) | ||
140 | ->method('updateEntry'); | ||
141 | |||
142 | $producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer') | ||
143 | ->disableOriginalConstructor() | ||
144 | ->getMock(); | ||
145 | |||
146 | $producer | ||
147 | ->expects($this->exactly(24)) | ||
148 | ->method('publish'); | ||
149 | |||
150 | $wallabagV2Import->setProducer($producer); | ||
151 | |||
152 | $res = $wallabagV2Import->setMarkAsRead(true)->import(); | ||
153 | |||
154 | $this->assertTrue($res); | ||
155 | $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 24], $wallabagV2Import->getSummary()); | ||
156 | } | ||
157 | |||
158 | public function testImportWithRedis() | ||
159 | { | ||
160 | $wallabagV2Import = $this->getWallabagV2Import(); | ||
161 | $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json'); | ||
162 | |||
163 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') | ||
164 | ->disableOriginalConstructor() | ||
165 | ->getMock(); | ||
166 | |||
167 | $entryRepo->expects($this->never()) | ||
168 | ->method('findByUrlAndUserId'); | ||
169 | |||
170 | $this->em | ||
171 | ->expects($this->never()) | ||
172 | ->method('getRepository'); | ||
173 | |||
174 | $this->contentProxy | ||
175 | ->expects($this->never()) | ||
176 | ->method('updateEntry'); | ||
177 | |||
178 | $factory = new RedisMockFactory(); | ||
179 | $redisMock = $factory->getAdapter('Predis\Client', true); | ||
180 | |||
181 | $queue = new RedisQueue($redisMock, 'wallabag_v2'); | ||
182 | $producer = new Producer($queue); | ||
183 | |||
184 | $wallabagV2Import->setProducer($producer); | ||
185 | |||
186 | $res = $wallabagV2Import->setMarkAsRead(true)->import(); | ||
187 | |||
188 | $this->assertTrue($res); | ||
189 | $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 24], $wallabagV2Import->getSummary()); | ||
190 | |||
191 | $this->assertNotEmpty($redisMock->lpop('wallabag_v2')); | ||
117 | } | 192 | } |
118 | 193 | ||
119 | public function testImportBadFile() | 194 | public function testImportBadFile() |
@@ -152,7 +227,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase | |||
152 | $res = $wallabagV2Import->import(); | 227 | $res = $wallabagV2Import->import(); |
153 | 228 | ||
154 | $this->assertFalse($res); | 229 | $this->assertFalse($res); |
155 | $this->assertEquals(['skipped' => 0, 'imported' => 0], $wallabagV2Import->getSummary()); | 230 | $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 0], $wallabagV2Import->getSummary()); |
156 | } | 231 | } |
157 | 232 | ||
158 | public function testImportWithExceptionFromGraby() | 233 | public function testImportWithExceptionFromGraby() |
@@ -181,6 +256,6 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase | |||
181 | $res = $wallabagV2Import->import(); | 256 | $res = $wallabagV2Import->import(); |
182 | 257 | ||
183 | $this->assertTrue($res); | 258 | $this->assertTrue($res); |
184 | $this->assertEquals(['skipped' => 24, 'imported' => 0], $wallabagV2Import->getSummary()); | 259 | $this->assertEquals(['skipped' => 22, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary()); |
185 | } | 260 | } |
186 | } | 261 | } |