| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Hateoas\Tests\Serializer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Hateoas\HateoasBuilder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Hateoas\Model\Embedded; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Hateoas\Model\Link; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Hateoas\Representation\CollectionRepresentation; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Hateoas\Serializer\JsonHalSerializer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Hateoas\Serializer\Metadata\EmbeddedPropertyMetadata; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Hateoas\Serializer\Metadata\RelationPropertyMetadata; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Hateoas\Tests\Fixtures\AdrienBrault; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use Hateoas\Tests\Fixtures\Foo1; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Hateoas\Tests\Fixtures\Foo2; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Hateoas\Tests\Fixtures\Foo3; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Hateoas\Tests\Fixtures\Gh236Foo; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use Hateoas\Tests\TestCase; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use JMS\Serializer\SerializationContext; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use Prophecy\Argument; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | class JsonHalSerializerTest extends TestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     public function testSerializeLinks() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         $links = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |             new Link('self', '/users/42', array('awesome' => 'exactly')), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |             new Link('foo', '/bar'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |             new Link('foo', '/baz'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |             new Link('bar', '/foo'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |             new Link('bar', '/baz'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |             new Link('bar', '/buzz'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         $expectedSerializedLinks = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |             'self' => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |                 'href' => '/users/42', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |                 'awesome' => 'exactly', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |             ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |             'foo' => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |                 array('href' => '/bar'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |                 array('href' => '/baz'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |             ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |             'bar' => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |                 array('href' => '/foo'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |                 array('href' => '/baz'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |                 array('href' => '/buzz'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |             ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         $contextProphecy = $this->prophesize('JMS\Serializer\SerializationContext'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         $jsonSerializationVisitorProphecy = $this->prophesize('JMS\Serializer\JsonSerializationVisitor'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         $jsonSerializationVisitorProphecy | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |             ->addData('_links', $expectedSerializedLinks) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |             ->shouldBeCalledTimes(1) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         $jsonHalSerializer = new JsonHalSerializer(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         $jsonHalSerializer->serializeLinks( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |             $links, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |             $jsonSerializationVisitorProphecy->reveal(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |             $contextProphecy->reveal() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     public function testSerializeEmbeddeds() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         $acceptArguments = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |             array('name' => 'John'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |             array('name' => 'Bar'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |             array('name' => 'Baz'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |             array('name' => 'Foo'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |             array('name' => 'Baz'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |             array('name' => 'Buzz'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         $contextProphecy = $this->prophesize('JMS\Serializer\SerializationContext'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         foreach ($acceptArguments as $arg) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |             $contextProphecy | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |                 ->accept($arg) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |                 ->willReturnArgument() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |             ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         $contextProphecy->pushPropertyMetadata(Argument::type('Hateoas\Serializer\Metadata\RelationPropertyMetadata'))->shouldBeCalled(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         $contextProphecy->popPropertyMetadata()->shouldBeCalled(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |         $embeddeds = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |             new Embedded('friend', array('name' => 'John'), new RelationPropertyMetadata()), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |             new Embedded('foo', array('name' => 'Bar'), new RelationPropertyMetadata()), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |             new Embedded('foo', array('name' => 'Baz'), new RelationPropertyMetadata()), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |             new Embedded('bar', array('name' => 'Foo'), new RelationPropertyMetadata()), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |             new Embedded('bar', array('name' => 'Baz'), new RelationPropertyMetadata()), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |             new Embedded('bar', array('name' => 'Buzz'), new RelationPropertyMetadata()), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |         $expectedEmbeddedded = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |             'friend' => array('name' => 'John'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |             'foo' => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |                 array('name' => 'Bar'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |                 array('name' => 'Baz'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |             ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |             'bar' => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |                 array('name' => 'Foo'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |                 array('name' => 'Baz'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |                 array('name' => 'Buzz'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |             ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |         $jsonSerializationVisitorProphecy = $this->prophesize('JMS\Serializer\JsonSerializationVisitor'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |         $jsonSerializationVisitorProphecy | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |             ->addData('_embedded', $expectedEmbeddedded) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |             ->shouldBeCalledTimes(1) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |         ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |         $jsonHalSerializer = new JsonHalSerializer(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |         $jsonHalSerializer->serializeEmbeddeds( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |             $embeddeds, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |             $jsonSerializationVisitorProphecy->reveal(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |             $contextProphecy->reveal() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |     public function testSerializeCuriesWithOneLinkShouldBeAnArray() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |         $links = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |             new Link('self',   '/users/42'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |             new Link('curies', '/rels/{rel}', array('name' => 'p')), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |         $expectedSerializedLinks = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |             'self' => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |                 'href' => '/users/42', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |             ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |             'curies' => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |                 array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |                     'href' => '/rels/{rel}', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |                     'name' => 'p', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |                 ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |             ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |         $contextProphecy = $this->prophesize('JMS\Serializer\SerializationContext'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |         $jsonSerializationVisitorProphecy = $this->prophesize('JMS\Serializer\JsonSerializationVisitor'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |         $jsonSerializationVisitorProphecy | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |             ->addData('_links', $expectedSerializedLinks) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |             ->shouldBeCalledTimes(1) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |         ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |         $jsonHalSerializer = new JsonHalSerializer(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |         $jsonHalSerializer->serializeLinks( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |             $links, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |             $jsonSerializationVisitorProphecy->reveal(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |             $contextProphecy->reveal() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |     public function testSerializeCuriesWithMultipleEntriesShouldBeAnArray() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |         $links = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |             new Link('self',   '/users/42'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |             new Link('curies', '/rels/{rel}', array('name' => 'p')), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |             new Link('curies', '/foo/rels/{rel}', array('name' => 'foo')), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |         $expectedSerializedLinks = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |             'self' => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |                 'href' => '/users/42', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |             ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |             'curies' => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |                 array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |                     'href' => '/rels/{rel}', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |                     'name' => 'p', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |                 ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |                 array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |                     'href' => '/foo/rels/{rel}', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |                     'name' => 'foo', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |                 ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |             ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |         $contextProphecy = $this->prophesize('JMS\Serializer\SerializationContext'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |         $jsonSerializationVisitorProphecy = $this->prophesize('JMS\Serializer\JsonSerializationVisitor'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |         $jsonSerializationVisitorProphecy | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |             ->addData('_links', $expectedSerializedLinks) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |             ->shouldBeCalledTimes(1) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |         ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |         $jsonHalSerializer = new JsonHalSerializer(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |         $jsonHalSerializer->serializeLinks( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |             $links, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |             $jsonSerializationVisitorProphecy->reveal(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |             $contextProphecy->reveal() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |     public function testSerializeAdrienBrault() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |         $hateoas      = HateoasBuilder::buildHateoas(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  |         $adrienBrault = new AdrienBrault(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  |         $this->assertSame( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |             <<<JSON | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  |     "first_name": "Adrien", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  |     "last_name": "Brault", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  |     "_links": { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  |         "self": { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  |             "href": "http:\/\/adrienbrault.fr" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  |         }, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  |         "computer": { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  |             "href": "http:\/\/www.apple.com\/macbook-pro\/" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  |         }, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  |         "dynamic-relation": { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  |             "href": "awesome!!!" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  |     }, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  |     "_embedded": { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  |         "computer": { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  |             "name": "MacBook Pro" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  |         }, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  |         "broken-computer": { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  |             "name": "Windows Computer" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  |         }, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 |  |  |         "smartphone": [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  |             { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  |                 "name": "iPhone 6" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  |             }, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  |             { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 |  |  |                 "name": "Nexus 5" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  |         ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 |  |  |         "dynamic-relation": [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 |  |  |             "wowowow" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 |  |  |         ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 |  |  | JSON | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  |             , | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 |  |  |             $this->json($hateoas->serialize($adrienBrault, 'json')) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 |  |  |     public function testSerializeInlineJson() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  |         $foo1 = new Foo1(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  |         $foo2 = new Foo2(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  |         $foo3 = new Foo3(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  |         $foo1->inline = $foo2; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  |         $foo2->inline = $foo3; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  |         $hateoas = HateoasBuilder::buildHateoas(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  |         $this->assertSame( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  |             <<<JSON | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  |     "_links": { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 |  |  |         "self3": { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  |             "href": "foo3" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 |  |  |         }, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 |  |  |         "self2": { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 |  |  |             "href": "foo2" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 |  |  |         }, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 |  |  |         "self1": { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 |  |  |             "href": "foo1" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 |  |  |     }, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 |  |  |     "_embedded": { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 |  |  |         "self3": "foo3", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 271 |  |  |         "self2": "foo2", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 272 |  |  |         "self1": "foo1" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 273 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 274 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 275 |  |  | JSON | 
            
                                                                                                            
                            
            
                                    
            
            
                | 276 |  |  |             , | 
            
                                                                                                            
                            
            
                                    
            
            
                | 277 |  |  |             $this->json($hateoas->serialize($foo1, 'json')) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 278 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 279 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 280 |  |  |  | 
            
                                                        
            
                                                                    
                                                                                                        
            
            
                | 281 |  | View Code Duplication |     public function testGh236() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 282 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 283 |  |  |         $data = new CollectionRepresentation([new Gh236Foo()]); | 
            
                                                        
            
                                    
            
            
                | 284 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 285 |  |  |         $hateoas = HateoasBuilder::buildHateoas(); | 
            
                                                        
            
                                    
            
            
                | 286 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 287 |  |  |         $this->assertSame( | 
            
                                                        
            
                                    
            
            
                | 288 |  |  |             <<<JSON | 
            
                                                        
            
                                    
            
            
                | 289 |  |  | { | 
            
                                                        
            
                                    
            
            
                | 290 |  |  |     "_embedded": { | 
            
                                                        
            
                                    
            
            
                | 291 |  |  |         "items": [ | 
            
                                                        
            
                                    
            
            
                | 292 |  |  |             { | 
            
                                                        
            
                                    
            
            
                | 293 |  |  |                 "a": { | 
            
                                                        
            
                                    
            
            
                | 294 |  |  |                     "xxx": "yyy" | 
            
                                                        
            
                                    
            
            
                | 295 |  |  |                 }, | 
            
                                                        
            
                                    
            
            
                | 296 |  |  |                 "_embedded": { | 
            
                                                        
            
                                    
            
            
                | 297 |  |  |                     "b_embed": { | 
            
                                                        
            
                                    
            
            
                | 298 |  |  |                         "xxx": "zzz" | 
            
                                                        
            
                                    
            
            
                | 299 |  |  |                     } | 
            
                                                        
            
                                    
            
            
                | 300 |  |  |                 } | 
            
                                                        
            
                                    
            
            
                | 301 |  |  |             } | 
            
                                                        
            
                                    
            
            
                | 302 |  |  |         ] | 
            
                                                        
            
                                    
            
            
                | 303 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 304 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 305 |  |  | JSON | 
            
                                                        
            
                                    
            
            
                | 306 |  |  |             , | 
            
                                                        
            
                                    
            
            
                | 307 |  |  |             $this->json( | 
            
                                                        
            
                                    
            
            
                | 308 |  |  |                 $hateoas->serialize($data, 'json', SerializationContext::create()->enableMaxDepthChecks()) | 
            
                                                        
            
                                    
            
            
                | 309 |  |  |             ) | 
            
                                                        
            
                                    
            
            
                | 310 |  |  |         ); | 
            
                                                        
            
                                    
            
            
                | 311 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 312 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 313 |  |  |  | 
            
                        
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.