createMock(core_kernel_classes_Class::class); $model = $this->createMock(Ontology::class); $model->expects($this->once()) ->method('getClass') ->with(ExcludedOSService::ROOT_CLASS) ->willReturn($class); $service = new ExcludedOSService(); $service->setModel($model); $this->assertEquals($class, $service->getRootClass()); } public function testGetListClass(): void { $name = 'fixture-os-name'; $resource = $this->createMock(core_kernel_classes_Resource::class); $class = $this->createMock(core_kernel_classes_Class::class); $class->expects($this->once()) ->method('searchInstances') ->with( [OntologyRdfs::RDFS_LABEL => $name], ['like' => false] ) ->willReturn([$resource]); $model = $this->createMock(Ontology::class); $model->expects($this->once()) ->method('getClass') ->with(ExcludedOSService::LIST_CLASS) ->willReturn($class); $service = new ExcludedOSService(); $service->setModel($model); $this->assertEquals($resource, $service->getListDefinitionByName($name)); } public function testGetNameProperty(): void { $property = $this->createMock(core_kernel_classes_Property::class); $model = $this->createMock(Ontology::class); $model->expects($this->once()) ->method('getProperty') ->with(ExcludedOSService::EXCLUDED_NAME) ->willReturn($property); $service = new ExcludedOSService(); $service->setModel($model); $this->assertEquals($property, $service->getNameProperty()); } public function testGetVersionProperty(): void { $property = $this->createMock(core_kernel_classes_Property::class); $model = $this->createMock(Ontology::class); $model->expects($this->once()) ->method('getProperty') ->with(ExcludedOSService::EXCLUDED_VERSION) ->willReturn($property); $service = new ExcludedOSService(); $service->setModel($model); $this->assertEquals($property, $service->getVersionProperty()); } public function testGetExclusionsByName() { $name = 'fixture-os-name'; $resource1 = $this->createMock(core_kernel_classes_Resource::class); $resource2 = $this->createMock(core_kernel_classes_Resource::class); $class = $this->createMock(core_kernel_classes_Class::class); $class->expects($this->once()) ->method('searchInstances') ->with( [OntologyRdfs::RDFS_LABEL => $name], ['like' => false] ) ->willReturn([$resource1, $resource2]); $model = $this->createMock(Ontology::class); $model->expects($this->once()) ->method('getClass') ->with(ExcludedOSService::ROOT_CLASS) ->willReturn($class); $service = new ExcludedOSService(); $service->setModel($model); $this->assertEquals([$resource1, $resource2], $service->getExclusionsByName($name)); } public function testGetExclusionsList() { $name = 'fixture-os-name'; $version = 'fixture-os-version'; $nameProperty = $this->createMock(core_kernel_classes_Property::class); $nameProperty->expects($this->once()) ->method('getLabel') ->willReturn($name); $versionProperty = $this->createMock(core_kernel_classes_Literal::class); $versionProperty->expects($this->once()) ->method('__toString') ->willReturn($version); $resource = $this->createMock(core_kernel_classes_Resource::class); $resource->expects($this->once()) ->method('getPropertiesValues') ->willReturn([ ExcludedOSService::EXCLUDED_NAME => [$nameProperty], ExcludedOSService::EXCLUDED_VERSION => [$versionProperty] ]); $class = $this->createMock(core_kernel_classes_Class::class); $class->expects($this->once()) ->method('getInstances') ->with(true) ->willReturn([$resource]); $model = $this->createMock(Ontology::class); $model->expects($this->once()) ->method('getClass') ->with(ExcludedOSService::ROOT_CLASS) ->willReturn($class); $model->expects($this->any()) ->method('getProperty') ->willReturn($this->createMock(core_kernel_classes_Property::class)); $service = new ExcludedOSService(); $service->setModel($model); $this->assertEquals([$name => [$version]], $service->getExclusionsList()); } }