assertSame($fixtures, iterator_to_array($collection->getIterator())); } public function testConstructAndJsonEncode() { $fixtures = [ new MediaRelation('item', 'uri1', 'label1'), new MediaRelation('media', 'uri2') ]; $collection = new MediaRelationCollection(...$fixtures); $this->assertSame(json_encode($fixtures), json_encode($collection)); } public function testAdd() { $addFixture1 = new MediaRelation('item', 'uri1', 'label1'); $addFixture2 = new MediaRelation('media', 'uri2'); $addFixture3 = new MediaRelation('media', 'uri3', 'toto'); $expected = [ $addFixture1, $addFixture2, $addFixture3 ]; $collection = (new MediaRelationCollection(...[$addFixture1])); $collection->add($addFixture2)->add($addFixture3); $this->assertSame(json_encode($expected), json_encode($collection)); } }