Skip to content

Commit 1e67f8b

Browse files
committed
Added basic test for getServices method of Config class
1 parent 80469a6 commit 1e67f8b

File tree

1 file changed

+90
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)