X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2FWallabag%2FImportBundle%2FImport%2FPocketImportTest.php;h=d6b9617e4ad5efecd63b496d8838bf36676f6283;hb=ef75e1220ebb76a8df019d946460ad612759f0bb;hp=41f9b51f2bd4108438d341ac5aa036d3b4eaacb6;hpb=23634d5d842dabcf5d7475e2becb7e127824239e;p=github%2Fwallabag%2Fwallabag.git diff --git a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php index 41f9b51f..d6b9617e 100644 --- a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php @@ -32,26 +32,10 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase { $this->user = new User(); - $this->tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface') - ->disableOriginalConstructor() - ->getMock(); - - $token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface') - ->disableOriginalConstructor() - ->getMock(); - $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') ->disableOriginalConstructor() ->getMock(); - $token->expects($this->once()) - ->method('getUser') - ->willReturn($this->user); - - $this->tokenStorage->expects($this->once()) - ->method('getToken') - ->willReturn($token); - $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') ->disableOriginalConstructor() ->getMock(); @@ -66,11 +50,11 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase ->willReturn($consumerKey); $pocket = new PocketImportMock( - $this->tokenStorage, $this->em, $this->contentProxy, $config ); + $pocket->setUser($this->user); $this->logHandler = new TestHandler(); $logger = new Logger('test', [$this->logHandler]); @@ -390,4 +374,55 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase $this->assertContains('PocketImport: Failed to import', $records[0]['message']); $this->assertEquals('ERROR', $records[0]['level_name']); } + + public function testImportWithExceptionFromGraby() + { + $client = new Client(); + + $mock = new Mock([ + new Response(200, ['Content-Type' => 'application/json'], Stream::factory(json_encode(['access_token' => 'wunderbar_token']))), + new Response(200, ['Content-Type' => 'application/json'], Stream::factory(' + { + "status": 1, + "list": { + "229279689": { + "resolved_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview" + } + } + } + ')), + ]); + + $client->getEmitter()->attach($mock); + + $pocketImport = $this->getPocketImport(); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->once()) + ->method('findByUrlAndUserId') + ->will($this->onConsecutiveCalls(false, true)); + + $this->em + ->expects($this->once()) + ->method('getRepository') + ->willReturn($entryRepo); + + $entry = new Entry($this->user); + + $this->contentProxy + ->expects($this->once()) + ->method('updateEntry') + ->will($this->throwException(new \Exception())); + + $pocketImport->setClient($client); + $pocketImport->authorize('wunderbar_code'); + + $res = $pocketImport->import(); + + $this->assertTrue($res); + $this->assertEquals(['skipped' => 1, 'imported' => 0], $pocketImport->getSummary()); + } }