From 3fa7141a1245b95f3a39dcc9439b35a7964e5aa2 Mon Sep 17 00:00:00 2001 From: "J. King" Date: Wed, 4 Mar 2020 08:08:18 -0500 Subject: [PATCH] Cleanup --- composer.json | 1 - composer.lock | 53 +----------------------------- tests/cases/JSON/JSONTest.php | 61 ++++++++++++++++++++++++++++------- 3 files changed, 50 insertions(+), 65 deletions(-) diff --git a/composer.json b/composer.json index 03e12c8..4aa0ff3 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,6 @@ "ext-json": "*", "ext-dom": "*", "ext-intl": "*", - "sabre/uri": "^2.0", "ralouphie/mimey": "^2.1", "psr/http-message": "^1.0" }, diff --git a/composer.lock b/composer.lock index 0faff87..e3bec91 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "d9af1379d5c9a22f374e013981a951b5", + "content-hash": "6dc5509246f40b1ac68e0ed4056e34a9", "packages": [ { "name": "psr/http-message", @@ -95,57 +95,6 @@ ], "description": "PHP package for converting file extensions to MIME types and vice versa.", "time": "2019-03-08T08:49:03+00:00" - }, - { - "name": "sabre/uri", - "version": "2.2.0", - "source": { - "type": "git", - "url": "https://github.com/sabre-io/uri.git", - "reference": "059d11012603be2e32ddb7543602965563ddbb09" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sabre-io/uri/zipball/059d11012603be2e32ddb7543602965563ddbb09", - "reference": "059d11012603be2e32ddb7543602965563ddbb09", - "shasum": "" - }, - "require": { - "php": "^7.1" - }, - "require-dev": { - "friendsofphp/php-cs-fixer": "~2.16.1", - "phpunit/phpunit": "^7 || ^8" - }, - "type": "library", - "autoload": { - "files": [ - "lib/functions.php" - ], - "psr-4": { - "Sabre\\Uri\\": "lib/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Evert Pot", - "email": "me@evertpot.com", - "homepage": "http://evertpot.com/", - "role": "Developer" - } - ], - "description": "Functions for making sense out of URIs.", - "homepage": "http://sabre.io/uri/", - "keywords": [ - "rfc3986", - "uri", - "url" - ], - "time": "2020-01-31T18:53:43+00:00" } ], "packages-dev": [ diff --git a/tests/cases/JSON/JSONTest.php b/tests/cases/JSON/JSONTest.php index 48d0439..e1a1669 100644 --- a/tests/cases/JSON/JSONTest.php +++ b/tests/cases/JSON/JSONTest.php @@ -6,16 +6,47 @@ declare(strict_types=1); namespace JKingWeb\Lax\TestCase\JSON; +/* Test format is as follows: + + Each test is a JSON object with the following keys: + + - `description`: a short human-readable description of the test + - `base_url`: A base URL against which relative URLs should be resolved + - `input`: The test input, as a string or directly as a JSON Feed structure + - `output`: The result of the parsing upon success; described in more detail below + - `exception`: The exception ID thrown upon failure + + The 'description' and 'input' keys along with either 'output' or 'exception' + are required for all tests. + + The test output is necessarily mangled due to the limits of JSON: + + - Any field which should be a URL should be written as a string, which + will be transformed accordingly + - Any collections should be represented as arrays of objects, which will + all be transformed accordingly + - Rich text can either be supplied as a string (which will yield a Text object + with plain-text content) or as an object with any of the properties of the + Text class listed + + The transformations as performed by the `makeFeed` and `makeEntry` methods + of the abstract test case. + +*/ + use JKingWeb\Lax\Entry; use JKingWeb\Lax\Parser\Exception; use JKingWeb\Lax\Parser\JSON\Feed as Parser; -use JKingWeb\Lax\Feed; -use JKingWeb\Lax\Text; use JKingWeb\Lax\Person\Person; use JKingWeb\Lax\Person\Collection as PersonCollection; +use JKingWeb\Lax\Feed; +use JKingWeb\Lax\Text; use JKingWeb\Lax\Url; -/** @covers JKingWeb\Lax\Parser\JSON\Feed */ +/** + * @covers JKingWeb\Lax\Parser\JSON\Feed + * @covers JKingWeb\Lax\Parser\JSON\Entry + */ class JSONTest extends \PHPUnit\Framework\TestCase { /** @dataProvider provideJSONFeedVersion1 */ public function testJSONFeedVersion1($input, string $type, $output): void { @@ -58,11 +89,7 @@ class JSONTest extends \PHPUnit\Framework\TestCase { } elseif ($k === "people") { $c = new PersonCollection; foreach ($v as $m) { - $p = new Person; - foreach ($m as $kk => $vv) { - $p->$kk = $vv; - } - $c[] = $p; + $c[] = $this->makePerson($m); } $f->$k = $c; } elseif ($k === "entries") { @@ -101,11 +128,21 @@ class JSONTest extends \PHPUnit\Framework\TestCase { return new Text($data); } $out = new Text; - foreach(["plain", "html", "xhtml", "loose"] as $k) { - if (isset($data[$k])) { - $out->$k = $data[$k]; - } + foreach ($data as $k => $v) { + $out->$k = $v; } return $out; } + + protected function makePerson(\stdClass $person): Person { + $p = new Person; + foreach ($person as $k => $v) { + if (in_array($k, ["url", "avatar"])) { + $p->$k = new Url($v); + } else { + $p->$k = $v; + } + } + return $p; + } } \ No newline at end of file