ConfigTest.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\WebapiAsync\Test\Unit\Model;
  8. use Magento\Framework\Serialize\SerializerInterface;
  9. use Magento\Webapi\Model\Cache\Type\Webapi;
  10. use Magento\Webapi\Model\Config as WebapiConfig;
  11. use Magento\WebapiAsync\Model\Config;
  12. use Magento\Webapi\Model\Config\Converter;
  13. class ConfigTest extends \PHPUnit\Framework\TestCase
  14. {
  15. /**
  16. * @var Config
  17. */
  18. private $config;
  19. /**
  20. * @var Webapi|\PHPUnit_Framework_MockObject_MockObject
  21. */
  22. private $webapiCacheMock;
  23. /**
  24. * @var WebapiConfig|\PHPUnit_Framework_MockObject_MockObject
  25. */
  26. private $configMock;
  27. /**
  28. * @var SerializerInterface|\PHPUnit_Framework_MockObject_MockObject
  29. */
  30. private $serializerMock;
  31. protected function setUp()
  32. {
  33. $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  34. $this->webapiCacheMock = $this->createMock(\Magento\Webapi\Model\Cache\Type\Webapi::class);
  35. $this->configMock = $this->createMock(WebapiConfig::class);
  36. $this->serializerMock = $this->createMock(SerializerInterface::class);
  37. $this->config = $objectManager->getObject(
  38. Config::class,
  39. [
  40. 'cache' => $this->webapiCacheMock,
  41. 'webApiConfig' => $this->configMock,
  42. 'serializer' => $this->serializerMock
  43. ]
  44. );
  45. }
  46. public function testGetServicesSetsTopicFromServiceContractName()
  47. {
  48. $services = [
  49. Converter::KEY_ROUTES => [
  50. '/V1/products' => [
  51. 'POST' => [
  52. 'service' => [
  53. 'class' => \Magento\Catalog\Api\ProductRepositoryInterface::class,
  54. 'method' => 'save',
  55. ]
  56. ]
  57. ]
  58. ]
  59. ];
  60. $this->configMock->expects($this->once())
  61. ->method('getServices')
  62. ->willReturn($services);
  63. /* example of what $this->config->getServices() returns
  64. $result = [
  65. 'async.V1.products.POST' => [
  66. 'interface' => 'Magento\Catalog\Api\ProductRepositoryInterface',
  67. 'method' => 'save',
  68. 'topic' => 'async.magento.catalog.api.productrepositoryinterface.save.post',
  69. ]
  70. ];
  71. */
  72. $result = $this->config->getServices();
  73. $expectedTopic = 'async.magento.catalog.api.productrepositoryinterface.save.post';
  74. $lookupKey = 'async.V1.products.POST';
  75. $this->assertArrayHasKey($lookupKey, $result);
  76. $this->assertEquals($result[$lookupKey]['topic'], $expectedTopic);
  77. }
  78. }