Attempt to fix tests again
This commit is contained in:
parent
015929b48d
commit
0fa54d9f7f
@ -195,7 +195,6 @@ final class JsonAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$organized[$type][$id] = $newItem;
|
$organized[$type][$id] = $newItem;
|
||||||
$organized[$type][$id]['original'] = $item;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Second pass, go through and fill missing relationships in the first pass
|
// Second pass, go through and fill missing relationships in the first pass
|
||||||
@ -215,7 +214,6 @@ final class JsonAPI {
|
|||||||
$relationship =& $organized[$type][$id]['relationships'][$relType];
|
$relationship =& $organized[$type][$id]['relationships'][$relType];
|
||||||
unset($relationship['links']);
|
unset($relationship['links']);
|
||||||
unset($relationship['data']);
|
unset($relationship['data']);
|
||||||
$relationship['foo'] = TRUE;
|
|
||||||
|
|
||||||
if ($relType === $dataType)
|
if ($relType === $dataType)
|
||||||
{
|
{
|
||||||
@ -255,16 +253,16 @@ final class JsonAPI {
|
|||||||
$inlined[$key][$itemId] = $item;
|
$inlined[$key][$itemId] = $item;
|
||||||
|
|
||||||
foreach($item['relationships'] as $type => $ids)
|
foreach($item['relationships'] as $type => $ids)
|
||||||
{
|
{
|
||||||
$inlined[$key][$itemId]['relationships'][$type] = [];
|
$inlined[$key][$itemId]['relationships'][$type] = [];
|
||||||
|
|
||||||
if ( ! array_key_exists($type, $included)) continue;
|
if ( ! array_key_exists($type, $included)) continue;
|
||||||
|
|
||||||
if (array_key_exists('data', $ids ))
|
if (array_key_exists('data', $ids ))
|
||||||
{
|
{
|
||||||
$ids = array_column($ids['data'], 'id');
|
$ids = array_column($ids['data'], 'id');
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($ids as $id)
|
foreach($ids as $id)
|
||||||
{
|
{
|
||||||
$inlined[$key][$itemId]['relationships'][$type][$id] = $included[$type][$id];
|
$inlined[$key][$itemId]['relationships'][$type][$id] = $included[$type][$id];
|
||||||
@ -326,12 +324,13 @@ final class JsonAPI {
|
|||||||
|
|
||||||
foreach($relationships as $key => $data)
|
foreach($relationships as $key => $data)
|
||||||
{
|
{
|
||||||
$organized[$key] = $organized[$key] ?? [];
|
|
||||||
if ( ! array_key_exists('data', $data))
|
if ( ! array_key_exists('data', $data))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$organized[$key] = $organized[$key] ?? [];
|
||||||
|
|
||||||
foreach ($data['data'] as $item)
|
foreach ($data['data'] as $item)
|
||||||
{
|
{
|
||||||
if (\is_array($item) && array_key_exists('id', $item))
|
if (\is_array($item) && array_key_exists('id', $item))
|
||||||
|
@ -21,11 +21,11 @@ use Aviat\Ion\Json;
|
|||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class JsonAPITest extends TestCase {
|
class JsonAPITest extends TestCase {
|
||||||
|
|
||||||
protected $startData;
|
protected $startData;
|
||||||
protected $organizedIncludes;
|
protected $organizedIncludes;
|
||||||
protected $inlineIncluded;
|
protected $inlineIncluded;
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$dir = __DIR__ . '/../test_data/JsonAPI';
|
$dir = __DIR__ . '/../test_data/JsonAPI';
|
||||||
@ -33,20 +33,24 @@ class JsonAPITest extends TestCase {
|
|||||||
$this->organizedIncludes = Json::decodeFile("{$dir}/organizedIncludes.json");
|
$this->organizedIncludes = Json::decodeFile("{$dir}/organizedIncludes.json");
|
||||||
$this->inlineIncluded = Json::decodeFile("{$dir}/inlineIncluded.json");
|
$this->inlineIncluded = Json::decodeFile("{$dir}/inlineIncluded.json");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testOrganizeIncludes()
|
public function testOrganizeIncludes()
|
||||||
{
|
{
|
||||||
$expected = $this->organizedIncludes;
|
$expected = $this->organizedIncludes;
|
||||||
$actual = JsonAPI::organizeIncludes($this->startData['included']);
|
$actual = JsonAPI::organizeIncludes($this->startData['included']);
|
||||||
|
|
||||||
|
// file_put_contents(__DIR__ . '/../test_data/JsonAPI/organizedIncludes.json', json_Encode($actual));
|
||||||
|
|
||||||
$this->assertEquals($expected, $actual);
|
$this->assertEquals($expected, $actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testInlineIncludedRelationships()
|
public function testInlineIncludedRelationships()
|
||||||
{
|
{
|
||||||
$expected = $this->inlineIncluded;
|
$expected = $this->inlineIncluded;
|
||||||
$actual = JsonAPI::inlineIncludedRelationships($this->organizedIncludes, 'anime');
|
$actual = JsonAPI::inlineIncludedRelationships($this->organizedIncludes, 'anime');
|
||||||
|
|
||||||
|
// file_put_contents(__DIR__ . '/../test_data/JsonAPI/inlineIncluded.json', json_Encode($actual));
|
||||||
|
|
||||||
$this->assertEquals($expected, $actual);
|
$this->assertEquals($expected, $actual);
|
||||||
}
|
}
|
||||||
}
|
}
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user