@@ -54,14 +54,24 @@ public function testItWillSerializeToHalJsonAnArrayOfObjects()
5454 "title": "post title 1",
5555 "body": "post body 1",
5656 "author_id": 4,
57- "comments": []
57+ "comments": [],
58+ "_links":{
59+ "self":{
60+ "href":"/post/1"
61+ }
62+ }
5863 },
5964 {
6065 "post_id": 2,
6166 "title": "post title 2",
6267 "body": "post body 2",
6368 "author_id": 5,
64- "comments": []
69+ "comments": [],
70+ "_links":{
71+ "self":{
72+ "href":"/post/2"
73+ }
74+ }
6575 }
6676 ]
6777}
@@ -278,7 +288,6 @@ public function testItWillSerializeToHalJsonAComplexObject()
278288 ]
279289 );
280290 $ transformer ->addMeta ('is_devel ' , true );
281- $ transformer ->setSelfUrl ('http://example.com/posts/9 ' );
282291 $ transformer ->setFirstUrl ('http://example.com/posts/1 ' );
283292 $ transformer ->setNextUrl ('http://example.com/posts/10 ' );
284293
@@ -339,7 +348,12 @@ public function testItWillSerializeToHalJsonASimpleObject()
339348 "user_id": "User 25",
340349 "created_at": "2015-07-23T12:48:00+02:00"
341350 }
342- ]
351+ ],
352+ "_links": {
353+ "self": {
354+ "href": "/post/1"
355+ }
356+ }
343357}
344358JSON ;
345359
@@ -401,7 +415,12 @@ public function testItWillRenamePropertiesFromClass()
401415 "user_id": "User 25",
402416 "created_at": "2015-07-23T12:48:00+02:00"
403417 }
404- ]
418+ ],
419+ "_links": {
420+ "self": {
421+ "href": "/post/1"
422+ }
423+ }
405424}
406425JSON ;
407426
@@ -461,7 +480,12 @@ public function testItWillHidePropertiesFromClass()
461480 "user_id": "User 25",
462481 "created_at": "2015-07-23T12:48:00+02:00"
463482 }
464- ]
483+ ],
484+ "_links": {
485+ "self": {
486+ "href": "/post/1"
487+ }
488+ }
465489}
466490JSON ;
467491
@@ -520,7 +544,12 @@ public function testTypeValueIsChangedByClassAlias()
520544 "user_id": "User 25",
521545 "created_at": "2015-07-23T12:48:00+02:00"
522546 }
523- ]
547+ ],
548+ "_links": {
549+ "self": {
550+ "href": "/post/1"
551+ }
552+ }
524553}
525554JSON ;
526555
@@ -579,7 +608,12 @@ public function testItIfFilteringOutKeys()
579608 "user_id": "User 25",
580609 "created_at": "2015-07-23T12:48:00+02:00"
581610 }
582- ]
611+ ],
612+ "_links":{
613+ "self":{
614+ "href":"/post/1"
615+ }
616+ }
583617}
584618JSON ;
585619
@@ -605,7 +639,7 @@ private function createSimplePost()
605639 return $ post ;
606640 }
607641
608- public function testItCanBuildUrlsFromClassNameOrClassAlias ()
642+ public function testItCanBuildSelfUrls ()
609643 {
610644 $ mappings = [
611645 [
@@ -623,15 +657,10 @@ public function testItCanBuildUrlsFromClassNameOrClassAlias()
623657 'postId ' ,
624658 ],
625659 'urls ' => [
626- // Mandatory
627- 'self ' => 'http://example.com/posts/{Message} ' ,
628- // Optional
629- 'comments ' => 'http://example.com/posts/{Message}/comments ' ,
660+ 'self ' => 'http://example.com/posts/{postId} ' ,
630661 ],
631662 // (Optional) Used by HAL+JSON
632663 'curies ' => [
633- 'name ' => 'example ' ,
634- 'href ' => 'http://example.com/docs/rels/{rel} ' ,
635664 ],
636665 ],
637666 [
@@ -643,14 +672,10 @@ public function testItCanBuildUrlsFromClassNameOrClassAlias()
643672 'userId ' ,
644673 ],
645674 'urls ' => [
646- 'self ' => 'http://example.com/users/{User} ' ,
647- 'friends ' => 'http://example.com/users/{User}/friends ' ,
648- 'comments ' => 'http://example.com/users/{User}/comments ' ,
675+ 'self ' => 'http://example.com/users/{userId} ' ,
649676 ],
650677 // (Optional) Used by HAL+JSON
651678 'curies ' => [
652- 'name ' => 'example ' ,
653- 'href ' => 'http://example.com/docs/rels/{rel} ' ,
654679 ],
655680 ],
656681 [
@@ -662,12 +687,10 @@ public function testItCanBuildUrlsFromClassNameOrClassAlias()
662687 'commentId ' ,
663688 ],
664689 'urls ' => [
665- 'self ' => 'http://example.com/comments/{Comment } ' ,
690+ 'self ' => 'http://example.com/comments/{commentId } ' ,
666691 ],
667692 // (Optional) Used by HAL+JSON
668693 'curies ' => [
669- 'name ' => 'example ' ,
670- 'href ' => 'http://example.com/docs/rels/{rel} ' ,
671694 ],
672695 ],
673696 ];
@@ -686,12 +709,6 @@ public function testItCanBuildUrlsFromClassNameOrClassAlias()
686709 "_links":{
687710 "self":{
688711 "href":"http://example.com/users/1"
689- },
690- "example:friends":{
691- "href":"http://example.com/users/1/friends"
692- },
693- "example:comments":{
694- "href":"http://example.com/users/1/comments"
695712 }
696713 }
697714 },
@@ -710,19 +727,13 @@ public function testItCanBuildUrlsFromClassNameOrClassAlias()
710727 "_links":{
711728 "self":{
712729 "href":"http://example.com/users/2"
713- },
714- "example:friends":{
715- "href":"http://example.com/users/2/friends"
716- },
717- "example:comments":{
718- "href":"http://example.com/users/2/comments"
719730 }
720731 }
721732 }
722733 },
723734 "_links":{
724- "example: user":{
725- "href":"http://example.com/users/2"
735+ "user":{
736+ "href":"http://example.com/users/2"
726737 },
727738 "self":{
728739 "href":"http://example.com/comments/1000"
@@ -732,35 +743,12 @@ public function testItCanBuildUrlsFromClassNameOrClassAlias()
732743 ]
733744 },
734745 "_links":{
735- "curies":[
736- {
737- "name":"example",
738- "href":"http://example.com/docs/rels/{rel}",
739- "templated":true
740- }
741- ],
746+ "author":{
747+ "href":"http://example.com/users/1"
748+ },
742749 "self":{
743750 "href":"http://example.com/posts/9"
744- },
745- "first":{
746- "href":"http://example.com/posts/1"
747- },
748- "next":{
749- "href":"http://example.com/posts/10"
750- },
751- "example:author":{
752- "href":"http://example.com/users/1"
753- },
754- "example:comments":{
755- "href":"http://example.com/posts/9/comments"
756751 }
757- },
758- "_meta":{
759- "author":{
760- "name":"Nil Portugués Calderó",
761- "email":"contact@nilportugues.com"
762- },
763- "is_devel":true
764752 }
765753}
766754JSON ;
@@ -786,18 +774,6 @@ public function testItCanBuildUrlsFromClassNameOrClassAlias()
786774 );
787775
788776 $ transformer = new JsonTransformer ($ mapper );
789- $ transformer ->setMeta (
790- [
791- 'author ' => [
792- 'name ' => 'Nil Portugués Calderó ' ,
793- 'email ' => 'contact@nilportugues.com ' ,
794- ],
795- ]
796- );
797- $ transformer ->addMeta ('is_devel ' , true );
798- $ transformer ->setSelfUrl ('http://example.com/posts/9 ' );
799- $ transformer ->setFirstUrl ('http://example.com/posts/1 ' );
800- $ transformer ->setNextUrl ('http://example.com/posts/10 ' );
801777
802778 $ this ->assertEquals (
803779 \json_decode ($ expected , true ),
0 commit comments