Skip to content

Commit 7479384

Browse files
committed
Add asserts for links and meta to ItemTest
1 parent b8780a0 commit 7479384

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

tests/ItemTest.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
use Swis\JsonApi\Client\Collection;
66
use Swis\JsonApi\Client\Item;
7+
use Swis\JsonApi\Client\Link;
8+
use Swis\JsonApi\Client\Links;
9+
use Swis\JsonApi\Client\Meta;
710
use Swis\JsonApi\Client\Tests\Mocks\Items\RelatedItem;
811
use Swis\JsonApi\Client\Tests\Mocks\Items\WithGetMutatorItem;
912
use Swis\JsonApi\Client\Tests\Mocks\Items\WithHiddenItem;
@@ -372,4 +375,66 @@ public function is_adds_empty_morphtomany_relation_in_to_json_api_array()
372375
$item->toJsonApiArray()
373376
);
374377
}
378+
379+
/**
380+
* @test
381+
*/
382+
public function is_adds_links_in_to_json_api_array()
383+
{
384+
$item = new Item();
385+
$item->setType('testType');
386+
$item->setId(1);
387+
$item->setLinks(
388+
new Links(
389+
[
390+
'self' => new Link(
391+
'http://example.com/testType/1',
392+
new Meta(['foo' => 'bar'])
393+
),
394+
'other' => new Link('http://example.com/testType/1/other'),
395+
]
396+
)
397+
);
398+
399+
$this->assertEquals(
400+
[
401+
'type' => 'testType',
402+
'id' => 1,
403+
'links' => [
404+
'self' => [
405+
'href' => 'http://example.com/testType/1',
406+
'meta' => [
407+
'foo' => 'bar',
408+
],
409+
],
410+
'other' => [
411+
'href' => 'http://example.com/testType/1/other',
412+
],
413+
],
414+
],
415+
$item->toJsonApiArray()
416+
);
417+
}
418+
419+
/**
420+
* @test
421+
*/
422+
public function is_adds_meta_in_to_json_api_array()
423+
{
424+
$item = new Item();
425+
$item->setType('testType');
426+
$item->setId(1);
427+
$item->setMeta(new Meta(['foo' => 'bar']));
428+
429+
$this->assertEquals(
430+
[
431+
'type' => 'testType',
432+
'id' => 1,
433+
'meta' => [
434+
'foo' => 'bar',
435+
],
436+
],
437+
$item->toJsonApiArray()
438+
);
439+
}
375440
}

0 commit comments

Comments
 (0)