aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php')
-rw-r--r--tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php97
1 files changed, 90 insertions, 7 deletions
diff --git a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php
index 706d707b..d98cd486 100644
--- a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php
+++ b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php
@@ -5,8 +5,11 @@ namespace Tests\Wallabag\ImportBundle\Import;
5use Wallabag\ImportBundle\Import\ReadabilityImport; 5use Wallabag\ImportBundle\Import\ReadabilityImport;
6use Wallabag\UserBundle\Entity\User; 6use Wallabag\UserBundle\Entity\User;
7use Wallabag\CoreBundle\Entity\Entry; 7use Wallabag\CoreBundle\Entity\Entry;
8use Wallabag\ImportBundle\Redis\Producer;
8use Monolog\Logger; 9use Monolog\Logger;
9use Monolog\Handler\TestHandler; 10use Monolog\Handler\TestHandler;
11use Simpleue\Queue\RedisQueue;
12use M6Web\Component\RedisMock\RedisMockFactory;
10 13
11class ReadabilityImportTest extends \PHPUnit_Framework_TestCase 14class ReadabilityImportTest extends \PHPUnit_Framework_TestCase
12{ 15{
@@ -58,9 +61,9 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase
58 ->disableOriginalConstructor() 61 ->disableOriginalConstructor()
59 ->getMock(); 62 ->getMock();
60 63
61 $entryRepo->expects($this->exactly(2)) 64 $entryRepo->expects($this->exactly(24))
62 ->method('findByUrlAndUserId') 65 ->method('findByUrlAndUserId')
63 ->will($this->onConsecutiveCalls(false, true)); 66 ->willReturn(false);
64 67
65 $this->em 68 $this->em
66 ->expects($this->any()) 69 ->expects($this->any())
@@ -72,14 +75,14 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase
72 ->getMock(); 75 ->getMock();
73 76
74 $this->contentProxy 77 $this->contentProxy
75 ->expects($this->exactly(1)) 78 ->expects($this->exactly(24))
76 ->method('updateEntry') 79 ->method('updateEntry')
77 ->willReturn($entry); 80 ->willReturn($entry);
78 81
79 $res = $readabilityImport->import(); 82 $res = $readabilityImport->import();
80 83
81 $this->assertTrue($res); 84 $this->assertTrue($res);
82 $this->assertEquals(['skipped' => 1, 'imported' => 1], $readabilityImport->getSummary()); 85 $this->assertEquals(['skipped' => 0, 'imported' => 24, 'queued' => 0], $readabilityImport->getSummary());
83 } 86 }
84 87
85 public function testImportAndMarkAllAsRead() 88 public function testImportAndMarkAllAsRead()
@@ -93,7 +96,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase
93 96
94 $entryRepo->expects($this->exactly(2)) 97 $entryRepo->expects($this->exactly(2))
95 ->method('findByUrlAndUserId') 98 ->method('findByUrlAndUserId')
96 ->will($this->onConsecutiveCalls(false, false)); 99 ->will($this->onConsecutiveCalls(false, true));
97 100
98 $this->em 101 $this->em
99 ->expects($this->any()) 102 ->expects($this->any())
@@ -101,7 +104,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase
101 ->willReturn($entryRepo); 104 ->willReturn($entryRepo);
102 105
103 $this->contentProxy 106 $this->contentProxy
104 ->expects($this->exactly(2)) 107 ->expects($this->exactly(1))
105 ->method('updateEntry') 108 ->method('updateEntry')
106 ->willReturn(new Entry($this->user)); 109 ->willReturn(new Entry($this->user));
107 110
@@ -117,7 +120,87 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase
117 120
118 $this->assertTrue($res); 121 $this->assertTrue($res);
119 122
120 $this->assertEquals(['skipped' => 0, 'imported' => 2], $readabilityImport->getSummary()); 123 $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $readabilityImport->getSummary());
124 }
125
126 public function testImportWithRabbit()
127 {
128 $readabilityImport = $this->getReadabilityImport();
129 $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability.json');
130
131 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
132 ->disableOriginalConstructor()
133 ->getMock();
134
135 $entryRepo->expects($this->never())
136 ->method('findByUrlAndUserId');
137
138 $this->em
139 ->expects($this->never())
140 ->method('getRepository');
141
142 $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry')
143 ->disableOriginalConstructor()
144 ->getMock();
145
146 $this->contentProxy
147 ->expects($this->never())
148 ->method('updateEntry');
149
150 $producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer')
151 ->disableOriginalConstructor()
152 ->getMock();
153
154 $producer
155 ->expects($this->exactly(24))
156 ->method('publish');
157
158 $readabilityImport->setProducer($producer);
159
160 $res = $readabilityImport->setMarkAsRead(true)->import();
161
162 $this->assertTrue($res);
163 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 24], $readabilityImport->getSummary());
164 }
165
166 public function testImportWithRedis()
167 {
168 $readabilityImport = $this->getReadabilityImport();
169 $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability.json');
170
171 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
172 ->disableOriginalConstructor()
173 ->getMock();
174
175 $entryRepo->expects($this->never())
176 ->method('findByUrlAndUserId');
177
178 $this->em
179 ->expects($this->never())
180 ->method('getRepository');
181
182 $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry')
183 ->disableOriginalConstructor()
184 ->getMock();
185
186 $this->contentProxy
187 ->expects($this->never())
188 ->method('updateEntry');
189
190 $factory = new RedisMockFactory();
191 $redisMock = $factory->getAdapter('Predis\Client', true);
192
193 $queue = new RedisQueue($redisMock, 'readability');
194 $producer = new Producer($queue);
195
196 $readabilityImport->setProducer($producer);
197
198 $res = $readabilityImport->setMarkAsRead(true)->import();
199
200 $this->assertTrue($res);
201 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 24], $readabilityImport->getSummary());
202
203 $this->assertNotEmpty($redisMock->lpop('readability'));
121 } 204 }
122 205
123 public function testImportBadFile() 206 public function testImportBadFile()