Browse Source

Test fix-up

master
J. King 4 years ago
parent
commit
de28c3faa3
  1. 6
      lib/Parser/JSON/Entry.php
  2. 2
      lib/Parser/JSON/Feed.php
  3. 5
      tests/cases/JSON/JSONTest.php
  4. 19
      tests/cases/JSON/entry.json

6
lib/Parser/JSON/Entry.php

@ -57,7 +57,7 @@ class Entry implements \JKingWeb\Lax\Parser\Entry {
return null;
} elseif (is_float($id)) {
if (!fmod($id, 1.0)) {
return (string) (int) $id;
return (string) (int) $id; // @codeCoverageIgnore
} else {
$id = preg_split("/E\+?/i", str_replace(localeconv()['decimal_point'], ".", (string) $id));
if (sizeof($id) === 1) {
@ -77,9 +77,9 @@ class Entry implements \JKingWeb\Lax\Parser\Entry {
}
while ($exp-- > 0) {
if ($mul && $dec) {
$int[] = array_shift($dec);
$int[] = array_shift($dec); // @codeCoverageIgnore
} elseif ($mul) {
$int[] = "0";
$int[] = "0"; // @codeCoverageIgnore
} elseif (!$mul && $int) {
array_unshift($dec, array_pop($int));
} else {

2
lib/Parser/JSON/Feed.php

@ -48,7 +48,7 @@ class Feed implements \JKingWeb\Lax\Parser\Feed {
if (strlen($type) && !in_array($type, self::MIME_TYPES)) {
throw new Exception("notJSONType");
}
$data = @json_decode($this->data, false, 20);
$data = @json_decode($this->data, false, 20, \JSON_BIGINT_AS_STRING | JSON_INVALID_UTF8_SUBSTITUTE);
if (!is_object($data)) {
throw new Exception("notJSON");
} elseif (!isset($data->version) || !preg_match("<^https://jsonfeed\.org/version/(\d+(?:\.\d+)?)$>", $data->version, $match)) {

5
tests/cases/JSON/JSONTest.php

@ -63,6 +63,7 @@ class JSONTest extends \PHPUnit\Framework\TestCase {
$act = $p->parse(new Feed);
$exp = $this->makeFeed($output);
$this->assertEquals($exp, $act);
$this->assertEqualsCanonicalizing($exp, $act);
}
}
@ -114,8 +115,10 @@ class JSONTest extends \PHPUnit\Framework\TestCase {
protected function makeEntry(\stdClass $entry): Entry {
$e = new Entry;
foreach ($entry as $k => $v) {
if (in_array($k, ["url", "link", "icon", "image"])) {
if (in_array($k, ["link", "relatedLink", "banner"])) {
$e->$k = new Url($v);
} elseif (in_array($k, ["title", "summary", "content"])) {
$e->$k = $this->makeText($v);
} else {
$e->$k = $v;
}

19
tests/cases/JSON/entry.json

@ -155,11 +155,11 @@
}
},
{
"description": "Integral float ID",
"description": "Simple float ID",
"input": {
"version": "https://jsonfeed.org/version/1",
"items": [{
"id": 0.003e3
"id": 0.3
}]
},
"output": {
@ -167,7 +167,20 @@
"version": "1",
"entries": [
{
"id": "3"
"id": "0.3"
}
]
}
},
{
"description": "Bignum ID",
"input": "{\"version\": \"https://jsonfeed.org/version/1\",\"items\": [{\"id\": 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999}]}",
"output": {
"format": "json",
"version": "1",
"entries": [
{
"id": "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"
}
]
}

Loading…
Cancel
Save