resourceRelationService = $this->createMock(ResourceRelationServiceInterface::class); $this->subject = new ResourceRelationServiceProxy(); $this->subject->setServiceLocator( $this->getServiceLocatorMock( [ 'serviceId' => $this->resourceRelationService, ] ) ); } public function testGetRelations(): void { $relation = new ResourceRelation( 'item', 'id', 'label' ); $collection = new ResourceRelationCollection(...[$relation]); $query = new FindAllQuery('itemId', null, 'item'); $this->subject->addService('item', 'serviceId'); $this->subject->addService('media', 'anotherServiceId'); $this->resourceRelationService ->method('findRelations') ->with($query) ->willReturn($collection); $iterator = $this->subject->findRelations($query)->getIterator(); $this->assertCount(1, $iterator->getArrayCopy()); $this->assertSame($relation, $iterator->offsetGet(0)); } public function testGetRelationsWillBeEmptyIfThereIsNoServiceMapped(): void { $query = new FindAllQuery('itemId', null, 'item'); $this->subject->addService('media', 'anotherServiceId'); $this->assertCount(0, $this->subject->findRelations($query)->getIterator()->getArrayCopy()); } public function testAddAndRemoveService(): void { $this->subject->addService('media', 'service1'); $this->subject->addService('media', 'service2'); $this->subject->addService('item', 'service3'); $this->subject->addService('item', 'service4'); $this->assertSame( [ 'service1', 'service2', ], $this->subject->getOption(ResourceRelationServiceProxy::OPTION_SERVICES)['media'] ); $this->assertSame( [ 'service3', 'service4', ], $this->subject->getOption(ResourceRelationServiceProxy::OPTION_SERVICES)['item'] ); $this->subject->removeService('media', 'service2'); $this->subject->removeService('item', 'service4'); $this->assertSame( [ 'service1', ], $this->subject->getOption(ResourceRelationServiceProxy::OPTION_SERVICES)['media'] ); $this->assertSame( [ 'service3', ], $this->subject->getOption(ResourceRelationServiceProxy::OPTION_SERVICES)['item'] ); } }