From 8f2038e5b15c2d7342ed18381531e5eb95e86d46 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Mon, 26 Nov 2018 22:22:49 +0100 Subject: Fix tests --- tests/Wallabag/ImportBundle/Command/ImportCommandTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'tests/Wallabag/ImportBundle') diff --git a/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php b/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php index f95320a4..8e1c528d 100644 --- a/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php +++ b/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php @@ -84,6 +84,8 @@ class ImportCommandTest extends WallabagCoreTestCase public function testRunImportCommandWithUserId() { + $this->logInAs('admin'); + $application = new Application($this->getClient()->getKernel()); $application->add(new ImportCommand()); @@ -92,7 +94,7 @@ class ImportCommandTest extends WallabagCoreTestCase $tester = new CommandTester($command); $tester->execute([ 'command' => $command->getName(), - 'username' => 1, + 'username' => $this->getLoggedInUserId(), 'filepath' => $application->getKernel()->getContainer()->getParameter('kernel.project_dir') . '/tests/Wallabag/ImportBundle/fixtures/wallabag-v2-read.json', '--useUserId' => true, '--importer' => 'v2', -- cgit v1.2.3 From 1e0d8ad7b728f6fb2cd886526b0fb84ef803e84f Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 17 Jan 2019 14:28:05 +0100 Subject: Enable PHPStan - Fix error for level 0 & 1 (level 7 has 699 errors...) - Add `updated_at` to site_credential (so the `timestamps()` method applies correctly) --- tests/Wallabag/ImportBundle/Consumer/AMQPEntryConsumerTest.php | 2 +- tests/Wallabag/ImportBundle/Consumer/RedisEntryConsumerTest.php | 2 +- tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php | 2 +- tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php | 2 +- tests/Wallabag/ImportBundle/Controller/InstapaperControllerTest.php | 4 ++-- tests/Wallabag/ImportBundle/Controller/PinboardControllerTest.php | 2 +- tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php | 2 +- tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php | 2 +- tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php | 4 ++-- 9 files changed, 11 insertions(+), 11 deletions(-) (limited to 'tests/Wallabag/ImportBundle') diff --git a/tests/Wallabag/ImportBundle/Consumer/AMQPEntryConsumerTest.php b/tests/Wallabag/ImportBundle/Consumer/AMQPEntryConsumerTest.php index b2141c04..b7f6192d 100644 --- a/tests/Wallabag/ImportBundle/Consumer/AMQPEntryConsumerTest.php +++ b/tests/Wallabag/ImportBundle/Consumer/AMQPEntryConsumerTest.php @@ -1,6 +1,6 @@ assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); $this->assertNotEmpty($content->getPreviewPicture(), 'Preview picture for http://www.usinenouvelle.com is ok'); $this->assertNotEmpty($content->getLanguage(), 'Language for http://www.usinenouvelle.com is ok'); - $this->assertSame(1, \count($content->getTags())); + $this->assertCount(1, $content->getTags()); $createdAt = $content->getCreatedAt(); $this->assertSame('2011', $createdAt->format('Y')); diff --git a/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php index dc5ed6d0..3e64f2e5 100644 --- a/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php @@ -122,7 +122,7 @@ class FirefoxControllerTest extends WallabagCoreTestCase $this->assertNotEmpty($content->getMimetype(), 'Mimetype for http://lexpansion.lexpress.fr is ok'); $this->assertNotEmpty($content->getPreviewPicture(), 'Preview picture for http://lexpansion.lexpress.fr is ok'); $this->assertNotEmpty($content->getLanguage(), 'Language for http://lexpansion.lexpress.fr is ok'); - $this->assertSame(3, \count($content->getTags())); + $this->assertCount(3, $content->getTags()); $content = $client->getContainer() ->get('doctrine.orm.entity_manager') diff --git a/tests/Wallabag/ImportBundle/Controller/InstapaperControllerTest.php b/tests/Wallabag/ImportBundle/Controller/InstapaperControllerTest.php index 7390fa88..05347767 100644 --- a/tests/Wallabag/ImportBundle/Controller/InstapaperControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/InstapaperControllerTest.php @@ -124,7 +124,7 @@ class InstapaperControllerTest extends WallabagCoreTestCase $this->assertNotEmpty($content->getPreviewPicture(), 'Preview picture for https://www.liberation.fr is ok'); $this->assertNotEmpty($content->getLanguage(), 'Language for https://www.liberation.fr is ok'); $this->assertContains('foot', $content->getTags(), 'It includes the "foot" tag'); - $this->assertSame(1, \count($content->getTags())); + $this->assertCount(1, $content->getTags()); $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt()); $content = $client->getContainer() @@ -138,7 +138,7 @@ class InstapaperControllerTest extends WallabagCoreTestCase $this->assertContains('foot', $content->getTags()); $this->assertContains('test_tag', $content->getTags()); - $this->assertSame(2, \count($content->getTags())); + $this->assertCount(2, $content->getTags()); } public function testImportInstapaperWithFileAndMarkAllAsRead() diff --git a/tests/Wallabag/ImportBundle/Controller/PinboardControllerTest.php b/tests/Wallabag/ImportBundle/Controller/PinboardControllerTest.php index 80819f45..15646d55 100644 --- a/tests/Wallabag/ImportBundle/Controller/PinboardControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/PinboardControllerTest.php @@ -127,7 +127,7 @@ class PinboardControllerTest extends WallabagCoreTestCase $this->assertContains('foot', $tags, 'It includes the "foot" tag'); $this->assertContains('varnish', $tags, 'It includes the "varnish" tag'); $this->assertContains('php', $tags, 'It includes the "php" tag'); - $this->assertSame(3, \count($tags)); + $this->assertCount(3, $tags); $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt()); $this->assertSame('2016-10-26', $content->getCreatedAt()->format('Y-m-d')); diff --git a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php index 5619659a..4f2f4053 100644 --- a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php @@ -125,7 +125,7 @@ class ReadabilityControllerTest extends WallabagCoreTestCase $tags = $content->getTags(); $this->assertContains('foot', $tags, 'It includes the "foot" tag'); - $this->assertSame(1, \count($tags)); + $this->assertCount(1, $tags); $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt()); $this->assertSame('2016-09-08', $content->getCreatedAt()->format('Y-m-d')); diff --git a/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php b/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php index c67941a7..1f57939d 100644 --- a/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php @@ -127,7 +127,7 @@ class WallabagV1ControllerTest extends WallabagCoreTestCase $tags = $content->getTags(); $this->assertContains('foot', $tags, 'It includes the "foot" tag'); $this->assertContains('framabag', $tags, 'It includes the "framabag" tag'); - $this->assertSame(2, \count($tags)); + $this->assertCount(2, $tags); $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt()); } diff --git a/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php b/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php index 822656ba..b606e26a 100644 --- a/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php @@ -128,7 +128,7 @@ class WallabagV2ControllerTest extends WallabagCoreTestCase $tags = $content->getTags(); $this->assertContains('foot', $tags, 'It includes the "foot" tag'); - $this->assertSame(1, \count($tags)); + $this->assertCount(1, $tags); $content = $client->getContainer() ->get('doctrine.orm.entity_manager') @@ -147,7 +147,7 @@ class WallabagV2ControllerTest extends WallabagCoreTestCase $this->assertContains('foot', $tags, 'It includes the "foot" tag'); $this->assertContains('mediapart', $tags, 'It includes the "mediapart" tag'); $this->assertContains('blog', $tags, 'It includes the "blog" tag'); - $this->assertSame(3, \count($tags)); + $this->assertCount(3, $tags); $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt()); $this->assertSame('2016-09-08', $content->getCreatedAt()->format('Y-m-d')); -- cgit v1.2.3 From d99e6423f4bd54595a8a805dd1efd0bd94e8bb09 Mon Sep 17 00:00:00 2001 From: nicofrand Date: Tue, 21 May 2019 20:10:57 +0200 Subject: [tests] Fix pre-existing tests (preview now imported + records added) --- tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/Wallabag/ImportBundle') diff --git a/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php b/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php index 1f57939d..2a8e7c89 100644 --- a/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php @@ -121,7 +121,7 @@ class WallabagV1ControllerTest extends WallabagCoreTestCase $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); $this->assertEmpty($content->getMimetype(), 'Mimetype for http://www.framablog.org is empty'); - $this->assertEmpty($content->getPreviewPicture(), 'Preview picture for http://www.framablog.org is empty'); + $this->assertSame($content->getPreviewPicture(), 'http://www.framablog.org/public/_img/framablog/wallaby_baby.jpg'); $this->assertEmpty($content->getLanguage(), 'Language for http://www.framablog.org is empty'); $tags = $content->getTags(); -- cgit v1.2.3 From bf9ace0643f654e7ccd9c020b8b501ad56cd19de Mon Sep 17 00:00:00 2001 From: adev Date: Tue, 24 Oct 2017 22:55:40 +0200 Subject: Use httplug --- .../ImportBundle/Import/PocketImportTest.php | 404 +++++++++------------ 1 file changed, 181 insertions(+), 223 deletions(-) (limited to 'tests/Wallabag/ImportBundle') diff --git a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php index 8083f1a8..ec76f168 100644 --- a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php @@ -2,10 +2,8 @@ namespace Tests\Wallabag\ImportBundle\Import; -use GuzzleHttp\Client; -use GuzzleHttp\Message\Response; -use GuzzleHttp\Stream\Stream; -use GuzzleHttp\Subscriber\Mock; +use Http\Mock\Client as HttpMockClient; +use GuzzleHttp\Psr7\Response; use M6Web\Component\RedisMock\RedisMockFactory; use Monolog\Handler\TestHandler; use Monolog\Logger; @@ -38,16 +36,11 @@ class PocketImportTest extends TestCase public function testOAuthRequest() { - $client = new Client(); - - $mock = new Mock([ - new Response(200, ['Content-Type' => 'application/json'], Stream::factory(json_encode(['code' => 'wunderbar_code']))), - ]); - - $client->getEmitter()->attach($mock); + $httpMockClient = new HttpMockClient(); + $httpMockClient->addResponse(new Response(200, ['Content-Type' => 'application/json'], json_encode(['code' => 'wunderbar_code']))); $pocketImport = $this->getPocketImport(); - $pocketImport->setClient($client); + $pocketImport->setClient($httpMockClient); $code = $pocketImport->getRequestToken('http://0.0.0.0/redirect'); @@ -56,16 +49,11 @@ class PocketImportTest extends TestCase public function testOAuthRequestBadResponse() { - $client = new Client(); - - $mock = new Mock([ - new Response(403), - ]); - - $client->getEmitter()->attach($mock); + $httpMockClient = new HttpMockClient(); + $httpMockClient->addResponse(new Response(403)); $pocketImport = $this->getPocketImport(); - $pocketImport->setClient($client); + $pocketImport->setClient($httpMockClient); $code = $pocketImport->getRequestToken('http://0.0.0.0/redirect'); @@ -78,16 +66,11 @@ class PocketImportTest extends TestCase public function testOAuthAuthorize() { - $client = new Client(); - - $mock = new Mock([ - new Response(200, ['Content-Type' => 'application/json'], Stream::factory(json_encode(['access_token' => 'wunderbar_token']))), - ]); - - $client->getEmitter()->attach($mock); + $httpMockClient = new HttpMockClient(); + $httpMockClient->addResponse(new Response(200, ['Content-Type' => 'application/json'], json_encode(['access_token' => 'wunderbar_token']))); $pocketImport = $this->getPocketImport(); - $pocketImport->setClient($client); + $pocketImport->setClient($httpMockClient); $res = $pocketImport->authorize('wunderbar_code'); @@ -97,16 +80,11 @@ class PocketImportTest extends TestCase public function testOAuthAuthorizeBadResponse() { - $client = new Client(); - - $mock = new Mock([ - new Response(403), - ]); - - $client->getEmitter()->attach($mock); + $httpMockClient = new HttpMockClient(); + $httpMockClient->addResponse(new Response(403)); $pocketImport = $this->getPocketImport(); - $pocketImport->setClient($client); + $pocketImport->setClient($httpMockClient); $res = $pocketImport->authorize('wunderbar_code'); @@ -122,94 +100,90 @@ class PocketImportTest extends TestCase */ public function testImport() { - $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": { - "item_id": "229279689", - "resolved_id": "229279689", - "given_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", - "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland", - "favorite": "1", - "status": "1", - "time_added": "1473020899", - "time_updated": "1473020899", - "time_read": "0", - "time_favorited": "0", - "sort_id": 0, - "resolved_title": "The Massive Ryder Cup Preview", - "resolved_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", - "excerpt": "The list of things I love about the Ryder Cup is so long that it could fill a (tedious) novel, and golf fans can probably guess most of them.", - "is_article": "1", - "is_index": "0", - "has_video": "1", - "has_image": "1", - "word_count": "3197", - "images": { - "1": { - "item_id": "229279689", - "image_id": "1", - "src": "http://a.espncdn.com/combiner/i?img=/photo/2012/0927/grant_g_ryder_cr_640.jpg&w=640&h=360", - "width": "0", - "height": "0", - "credit": "Jamie Squire/Getty Images", - "caption": "" - } - }, - "videos": { - "1": { - "item_id": "229279689", - "video_id": "1", - "src": "http://www.youtube.com/v/Er34PbFkVGk?version=3&hl=en_US&rel=0", - "width": "420", - "height": "315", - "type": "1", - "vid": "Er34PbFkVGk" - } - }, - "tags": { - "grantland": { - "item_id": "1147652870", - "tag": "grantland" - }, - "Ryder Cup": { - "item_id": "1147652870", - "tag": "Ryder Cup" - } + $httpMockClient = new HttpMockClient(); + $httpMockClient->addResponse(new Response(200, ['Content-Type' => 'application/json'], json_encode(['access_token' => 'wunderbar_token']))); + $httpMockClient->addResponse(new Response(200, ['Content-Type' => 'application/json'], <<<'JSON' + { + "status": 1, + "list": { + "229279689": { + "item_id": "229279689", + "resolved_id": "229279689", + "given_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", + "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland", + "favorite": "1", + "status": "1", + "time_added": "1473020899", + "time_updated": "1473020899", + "time_read": "0", + "time_favorited": "0", + "sort_id": 0, + "resolved_title": "The Massive Ryder Cup Preview", + "resolved_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", + "excerpt": "The list of things I love about the Ryder Cup is so long that it could fill a (tedious) novel, and golf fans can probably guess most of them.", + "is_article": "1", + "is_index": "0", + "has_video": "1", + "has_image": "1", + "word_count": "3197", + "images": { + "1": { + "item_id": "229279689", + "image_id": "1", + "src": "http://a.espncdn.com/combiner/i?img=/photo/2012/0927/grant_g_ryder_cr_640.jpg&w=640&h=360", + "width": "0", + "height": "0", + "credit": "Jamie Squire/Getty Images", + "caption": "" } }, - "229279690": { - "item_id": "229279689", - "resolved_id": "229279689", - "given_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", - "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland", - "favorite": "1", - "status": "1", - "time_added": "1473020899", - "time_updated": "1473020899", - "time_read": "0", - "time_favorited": "0", - "sort_id": 1, - "resolved_title": "The Massive Ryder Cup Preview", - "resolved_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", - "excerpt": "The list of things I love about the Ryder Cup is so long that it could fill a (tedious) novel, and golf fans can probably guess most of them.", - "is_article": "1", - "is_index": "0", - "has_video": "0", - "has_image": "0", - "word_count": "3197" + "videos": { + "1": { + "item_id": "229279689", + "video_id": "1", + "src": "http://www.youtube.com/v/Er34PbFkVGk?version=3&hl=en_US&rel=0", + "width": "420", + "height": "315", + "type": "1", + "vid": "Er34PbFkVGk" + } + }, + "tags": { + "grantland": { + "item_id": "1147652870", + "tag": "grantland" + }, + "Ryder Cup": { + "item_id": "1147652870", + "tag": "Ryder Cup" + } } + }, + "229279690": { + "item_id": "229279689", + "resolved_id": "229279689", + "given_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", + "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland", + "favorite": "1", + "status": "1", + "time_added": "1473020899", + "time_updated": "1473020899", + "time_read": "0", + "time_favorited": "0", + "sort_id": 1, + "resolved_title": "The Massive Ryder Cup Preview", + "resolved_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", + "excerpt": "The list of things I love about the Ryder Cup is so long that it could fill a (tedious) novel, and golf fans can probably guess most of them.", + "is_article": "1", + "is_index": "0", + "has_video": "0", + "has_image": "0", + "word_count": "3197" } } - ')), - ]); - - $client->getEmitter()->attach($mock); + } +JSON +)); $pocketImport = $this->getPocketImport('ConsumerKey', 1); @@ -240,7 +214,7 @@ class PocketImportTest extends TestCase ->method('updateEntry') ->willReturn($entry); - $pocketImport->setClient($client); + $pocketImport->setClient($httpMockClient); $pocketImport->authorize('wunderbar_code'); $res = $pocketImport->import(); @@ -254,56 +228,52 @@ class PocketImportTest extends TestCase */ public function testImportAndMarkAllAsRead() { - $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": { - "item_id": "229279689", - "resolved_id": "229279689", - "given_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", - "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland", - "favorite": "1", - "status": "1", - "time_added": "1473020899", - "time_updated": "1473020899", - "time_read": "0", - "time_favorited": "0", - "sort_id": 0, - "excerpt": "The list of things I love about the Ryder Cup is so long that it could fill a (tedious) novel, and golf fans can probably guess most of them.", - "is_article": "1", - "has_video": "1", - "has_image": "1", - "word_count": "3197" - }, - "229279690": { - "item_id": "229279689", - "resolved_id": "229279689", - "given_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview/2", - "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland", - "favorite": "1", - "status": "0", - "time_added": "1473020899", - "time_updated": "1473020899", - "time_read": "0", - "time_favorited": "0", - "sort_id": 1, - "excerpt": "The list of things I love about the Ryder Cup is so long that it could fill a (tedious) novel, and golf fans can probably guess most of them.", - "is_article": "1", - "has_video": "0", - "has_image": "0", - "word_count": "3197" - } + $httpMockClient = new HttpMockClient(); + $httpMockClient->addResponse(new Response(200, ['Content-Type' => 'application/json'], json_encode(['access_token' => 'wunderbar_token']))); + $httpMockClient->addResponse(new Response(200, ['Content-Type' => 'application/json'], <<<'JSON' + { + "status": 1, + "list": { + "229279689": { + "item_id": "229279689", + "resolved_id": "229279689", + "given_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", + "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland", + "favorite": "1", + "status": "1", + "time_added": "1473020899", + "time_updated": "1473020899", + "time_read": "0", + "time_favorited": "0", + "sort_id": 0, + "excerpt": "The list of things I love about the Ryder Cup is so long that it could fill a (tedious) novel, and golf fans can probably guess most of them.", + "is_article": "1", + "has_video": "1", + "has_image": "1", + "word_count": "3197" + }, + "229279690": { + "item_id": "229279689", + "resolved_id": "229279689", + "given_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview/2", + "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland", + "favorite": "1", + "status": "0", + "time_added": "1473020899", + "time_updated": "1473020899", + "time_read": "0", + "time_favorited": "0", + "sort_id": 1, + "excerpt": "The list of things I love about the Ryder Cup is so long that it could fill a (tedious) novel, and golf fans can probably guess most of them.", + "is_article": "1", + "has_video": "0", + "has_image": "0", + "word_count": "3197" } } - ')), - ]); - - $client->getEmitter()->attach($mock); + } +JSON +)); $pocketImport = $this->getPocketImport('ConsumerKey', 2); @@ -335,7 +305,7 @@ class PocketImportTest extends TestCase ->method('updateEntry') ->willReturn($entry); - $pocketImport->setClient($client); + $pocketImport->setClient($httpMockClient); $pocketImport->authorize('wunderbar_code'); $res = $pocketImport->setMarkAsRead(true)->import(); @@ -349,7 +319,7 @@ class PocketImportTest extends TestCase */ public function testImportWithRabbit() { - $client = new Client(); + $httpMockClient = new HttpMockClient(); $body = <<<'JSON' { @@ -374,19 +344,16 @@ class PocketImportTest extends TestCase } JSON; - $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": { - "229279690": ' . $body . ' - } + $httpMockClient->addResponse(new Response(200, ['Content-Type' => 'application/json'], json_encode(['access_token' => 'wunderbar_token']))); + $httpMockClient->addResponse(new Response(200, ['Content-Type' => 'application/json'], <<getEmitter()->attach($mock); + } +JSON + )); $pocketImport = $this->getPocketImport(); @@ -420,7 +387,7 @@ JSON; ->method('publish') ->with(json_encode($bodyAsArray)); - $pocketImport->setClient($client); + $pocketImport->setClient($httpMockClient); $pocketImport->setProducer($producer); $pocketImport->authorize('wunderbar_code'); @@ -435,7 +402,7 @@ JSON; */ public function testImportWithRedis() { - $client = new Client(); + $httpMockClient = new HttpMockClient(); $body = <<<'JSON' { @@ -460,19 +427,16 @@ JSON; } JSON; - $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": { - "229279690": ' . $body . ' - } + $httpMockClient->addResponse(new Response(200, ['Content-Type' => 'application/json'], json_encode(['access_token' => 'wunderbar_token']))); + $httpMockClient->addResponse(new Response(200, ['Content-Type' => 'application/json'], <<getEmitter()->attach($mock); + } +JSON + )); $pocketImport = $this->getPocketImport(); @@ -499,7 +463,7 @@ JSON; $queue = new RedisQueue($redisMock, 'pocket'); $producer = new Producer($queue); - $pocketImport->setClient($client); + $pocketImport->setClient($httpMockClient); $pocketImport->setProducer($producer); $pocketImport->authorize('wunderbar_code'); @@ -513,17 +477,13 @@ JSON; public function testImportBadResponse() { - $client = new Client(); + $httpMockClient = new HttpMockClient(); - $mock = new Mock([ - new Response(200, ['Content-Type' => 'application/json'], Stream::factory(json_encode(['access_token' => 'wunderbar_token']))), - new Response(403), - ]); - - $client->getEmitter()->attach($mock); + $httpMockClient->addResponse(new Response(200, ['Content-Type' => 'application/json'], json_encode(['access_token' => 'wunderbar_token']))); + $httpMockClient->addResponse(new Response(403)); $pocketImport = $this->getPocketImport(); - $pocketImport->setClient($client); + $pocketImport->setClient($httpMockClient); $pocketImport->authorize('wunderbar_code'); $res = $pocketImport->import(); @@ -537,25 +497,23 @@ JSON; 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": { - "status": "1", - "favorite": "1", - "resolved_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview" - } + $httpMockClient = new HttpMockClient(); + + $httpMockClient->addResponse(new Response(200, ['Content-Type' => 'application/json'], json_encode(['access_token' => 'wunderbar_token']))); + $httpMockClient->addResponse(new Response(200, ['Content-Type' => 'application/json'], <<<'JSON' + { + "status": 1, + "list": { + "229279689": { + "status": "1", + "favorite": "1", + "resolved_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview" } } - ')), - ]); - - $client->getEmitter()->attach($mock); + } + +JSON + )); $pocketImport = $this->getPocketImport('ConsumerKey', 1); @@ -579,7 +537,7 @@ JSON; ->method('updateEntry') ->will($this->throwException(new \Exception())); - $pocketImport->setClient($client); + $pocketImport->setClient($httpMockClient); $pocketImport->authorize('wunderbar_code'); $res = $pocketImport->import(); -- cgit v1.2.3 From 448d99f84e93697ce49ec31224addb1da1a37a9f Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Mon, 28 Jan 2019 06:10:26 +0100 Subject: CS --- tests/Wallabag/ImportBundle/Import/PocketImportTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/Wallabag/ImportBundle') diff --git a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php index ec76f168..40e1626b 100644 --- a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php @@ -2,8 +2,8 @@ namespace Tests\Wallabag\ImportBundle\Import; -use Http\Mock\Client as HttpMockClient; use GuzzleHttp\Psr7\Response; +use Http\Mock\Client as HttpMockClient; use M6Web\Component\RedisMock\RedisMockFactory; use Monolog\Handler\TestHandler; use Monolog\Logger; -- cgit v1.2.3