subject = new ResourceRelationCollection( ...[ (new ResourceRelation('item', '123', 'label item'))->withSourceId('456'), ] ); $this->subject->add((new ResourceRelation('media', '321', 'label media'))->withSourceId('654')); } public function testGetIterator(): void { $this->assertSame(2, $this->subject->getIterator()->count()); $this->assertInstanceOf(ResourceRelation::class, $this->subject->getIterator()->offsetGet(0)); $this->assertInstanceOf(ResourceRelation::class, $this->subject->getIterator()->offsetGet(1)); } public function testJsonSerialize(): void { $this->assertSame( [ [ 'type' => 'item', 'id' => '123', 'label' => 'label item', ], [ 'type' => 'media', 'id' => '321', 'label' => 'label media', ] ], json_decode(json_encode($this->subject->jsonSerialize()), true) ); } public function testFilterRemovedSourceIds(): void { $this->assertSame( [ '654' ], array_values( $this->subject->filterRemovedSourceIds( [ '456' ] ) ) ); $this->assertSame( [], $this->subject->filterRemovedSourceIds( [ '456', '654' ] ) ); } public function testFilterNewSourceIds(): void { $this->assertSame( [ '777' ], array_values( $this->subject->filterNewSourceIds( [ '777', '456', '654', ] ) ) ); $this->assertSame( [], $this->subject->filterNewSourceIds( [ '456', '654' ] ) ); } }