webapiCacheMock = $this->createMock(\Magento\Webapi\Model\Cache\Type\Webapi::class); $this->configMock = $this->createMock(WebapiConfig::class); $this->serializerMock = $this->createMock(SerializerInterface::class); $this->config = $objectManager->getObject( Config::class, [ 'cache' => $this->webapiCacheMock, 'webApiConfig' => $this->configMock, 'serializer' => $this->serializerMock ] ); } public function testGetServicesSetsTopicFromServiceContractName() { $services = [ Converter::KEY_ROUTES => [ '/V1/products' => [ 'POST' => [ 'service' => [ 'class' => \Magento\Catalog\Api\ProductRepositoryInterface::class, 'method' => 'save', ] ] ] ] ]; $this->configMock->expects($this->once()) ->method('getServices') ->willReturn($services); /* example of what $this->config->getServices() returns $result = [ 'async.V1.products.POST' => [ 'interface' => 'Magento\Catalog\Api\ProductRepositoryInterface', 'method' => 'save', 'topic' => 'async.magento.catalog.api.productrepositoryinterface.save.post', ] ]; */ $result = $this->config->getServices(); $expectedTopic = 'async.magento.catalog.api.productrepositoryinterface.save.post'; $lookupKey = 'async.V1.products.POST'; $this->assertArrayHasKey($lookupKey, $result); $this->assertEquals($result[$lookupKey]['topic'], $expectedTopic); } }