From d030a50bba7f9c179cfa5652c024424ec98d9bbf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9r=C3=A9my=20DECOOL?=
Date: Mon, 29 May 2017 01:09:35 +0200
Subject: [PATCH] Extract JSON test data into fixture files
---
test/Fixtures/microblog.json | 20 +++++++
test/Fixtures/podcast.json | 26 ++++++++
test/Fixtures/simple.json | 18 ++++++
test/Writer/Version1/RendererTest.php | 85 +++++----------------------
4 files changed, 79 insertions(+), 70 deletions(-)
create mode 100644 test/Fixtures/microblog.json
create mode 100644 test/Fixtures/podcast.json
create mode 100644 test/Fixtures/simple.json
diff --git a/test/Fixtures/microblog.json b/test/Fixtures/microblog.json
new file mode 100644
index 0000000..4fd749e
--- /dev/null
+++ b/test/Fixtures/microblog.json
@@ -0,0 +1,20 @@
+{
+ "version": "https://jsonfeed.org/version/1",
+ "user_comment": "This is a microblog feed. You can add this to your feed reader using the following URL: https://example.org/feed.json",
+ "title": "Brent Simmons’s Microblog",
+ "home_page_url": "https://example.org/",
+ "feed_url": "https://example.org/feed.json",
+ "author": {
+ "name": "Brent Simmons",
+ "url": "http://example.org/",
+ "avatar": "https://example.org/avatar.png"
+ },
+ "items": [
+ {
+ "id": "2347259",
+ "url": "https://example.org/2347259",
+ "content_text": "Cats are neat. https://example.org/cats",
+ "date_published": "2016-02-09T14:22:00+02:00"
+ }
+ ]
+}
diff --git a/test/Fixtures/podcast.json b/test/Fixtures/podcast.json
new file mode 100644
index 0000000..6a26183
--- /dev/null
+++ b/test/Fixtures/podcast.json
@@ -0,0 +1,26 @@
+{
+ "version": "https://jsonfeed.org/version/1",
+ "user_comment": "This is a podcast feed. You can add this feed to your podcast client using the following URL: http://therecord.co/feed.json",
+ "title": "The Record",
+ "home_page_url": "http://therecord.co/",
+ "feed_url": "http://therecord.co/feed.json",
+ "items": [
+ {
+ "id": "http://therecord.co/chris-parrish",
+ "title": "Special #1 - Chris Parrish",
+ "url": "http://therecord.co/chris-parrish",
+ "content_text": "Chris has worked at Adobe and as a founder of Rogue Sheep, which won an Apple Design Award for Postage. Chris’s new company is Aged & Distilled with Guy English — which shipped Napkin, a Mac app for visual collaboration. Chris is also the co-host of The Record. He lives on Bainbridge Island, a quick ferry ride from Seattle.",
+ "content_html": "Chris has worked at Adobe and as a founder of Rogue Sheep, which won an Apple Design Award for Postage. Chris’s new company is Aged & Distilled with Guy English — which shipped Napkin, a Mac app for visual collaboration. Chris is also the co-host of The Record. He lives on Bainbridge Island, a quick ferry ride from Seattle.",
+ "summary": "Brent interviews Chris Parrish, co-host of The Record and one-half of Aged & Distilled.",
+ "date_published": "2014-05-09T14:04:00-07:00",
+ "attachments": [
+ {
+ "url": "http://therecord.co/downloads/The-Record-sp1e1-ChrisParrish.m4a",
+ "mime_type": "audio/x-m4a",
+ "size_in_bytes": 89970236,
+ "duration_in_seconds": 6629
+ }
+ ]
+ }
+ ]
+}
diff --git a/test/Fixtures/simple.json b/test/Fixtures/simple.json
new file mode 100644
index 0000000..b895db8
--- /dev/null
+++ b/test/Fixtures/simple.json
@@ -0,0 +1,18 @@
+{
+ "version": "https://jsonfeed.org/version/1",
+ "title": "My Example Feed",
+ "home_page_url": "https://example.org/",
+ "feed_url": "https://example.org/feed.json",
+ "items": [
+ {
+ "id": "2",
+ "content_text": "This is a second item.",
+ "url": "https://example.org/second-item"
+ },
+ {
+ "id": "1",
+ "content_html": "Hello, world!
",
+ "url": "https://example.org/initial-post"
+ }
+ ]
+}
diff --git a/test/Writer/Version1/RendererTest.php b/test/Writer/Version1/RendererTest.php
index 5709c00..4cda77a 100644
--- a/test/Writer/Version1/RendererTest.php
+++ b/test/Writer/Version1/RendererTest.php
@@ -13,6 +13,13 @@
class RendererTest extends TestCase
{
+ private static $fixturesPath;
+
+ public static function setUpBeforeClass()
+ {
+ self::$fixturesPath = realpath(__DIR__.'/../../Fixtures');
+ }
+
public function testSimpleFeed()
{
$feed = new Feed('My Example Feed');
@@ -29,26 +36,7 @@ public function testSimpleFeed()
$item1->setUrl('https://example.org/initial-post');
$feed->addItem($item1);
- $expected = <<Hello, world!
",
- "url": "https://example.org/initial-post"
- }
- ]
-}
-JSON;
+ $expected = $this->getFixtures('simple');
$render = new Renderer();
$this->assertJsonStringEqualsJsonString($expected, $render->render($feed));
@@ -75,34 +63,7 @@ public function testPodcastFeed()
$feed->setFeedUrl('http://therecord.co/feed.json');
$feed->addItem($item);
- $expected = <<Adobe and as a founder of Rogue Sheep, which won an Apple Design Award for Postage. Chris’s new company is Aged & Distilled with Guy English — which shipped Napkin, a Mac app for visual collaboration. Chris is also the co-host of The Record. He lives on Bainbridge Island, a quick ferry ride from Seattle.",
- "summary": "Brent interviews Chris Parrish, co-host of The Record and one-half of Aged & Distilled.",
- "date_published": "2014-05-09T14:04:00-07:00",
- "attachments": [
- {
- "url": "http://therecord.co/downloads/The-Record-sp1e1-ChrisParrish.m4a",
- "mime_type": "audio/x-m4a",
- "size_in_bytes": 89970236,
- "duration_in_seconds": 6629
- }
- ]
- }
- ]
-}
-JSON;
+ $expected = $this->getFixtures('podcast');
$render = new Renderer();
$this->assertJsonStringEqualsJsonString($expected, $render->render($feed));
@@ -126,30 +87,14 @@ public function testMicroblogFeed()
$feed->setAuthor($author);
$feed->addItem($item);
- $expected = <<getFixtures('microblog');
$render = new Renderer();
$this->assertJsonStringEqualsJsonString($expected, $render->render($feed));
}
+
+ private function getFixtures($name)
+ {
+ return file_get_contents(self::$fixturesPath.'/'.$name.'.json');
+ }
}