Skip to content

Commit 8bf4e43

Browse files
authored
Merge pull request #16 from magento-lynx/MC-40572
MC-40572: Stabilize Unit tests (ASI)
2 parents ae116dc + 7a32b0e commit 8bf4e43

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

AdobeStockAdminUi/Test/Unit/Controller/Adminhtml/System/Config/TestConnectionTest.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
use Magento\AdobeStockAdminUi\Controller\Adminhtml\System\Config\TestConnection;
1111
use Magento\AdobeStockClientApi\Api\ClientInterface;
12+
use Magento\Backend\App\Action\Context;
13+
use Magento\Framework\App\RequestInterface;
1214
use Magento\Framework\Controller\Result\Json;
1315
use Magento\Framework\Controller\Result\JsonFactory;
1416
use Magento\Framework\Filter\StripTags;
@@ -42,6 +44,11 @@ class TestConnectionTest extends TestCase
4244
*/
4345
private $stripTagsMock;
4446

47+
/**
48+
* @var RequestInterface|MockObject
49+
*/
50+
private $request;
51+
4552
/**
4653
* @var TestConnection
4754
*/
@@ -53,15 +60,21 @@ class TestConnectionTest extends TestCase
5360
protected function setUp(): void
5461
{
5562
$this->objectManager = new ObjectManager($this);
56-
$this->clientMock = $this->getMockForAbstractClass(ClientInterface::class);
63+
$context = $this->createMock(Context::class);
64+
$this->request = $this->createMock(RequestInterface::class);
65+
$context->expects($this->once())
66+
->method('getRequest')
67+
->willReturn($this->request);
68+
$this->clientMock = $this->createMock(ClientInterface::class);
5769
$this->resultJsonFactoryMock = $this->createMock(JsonFactory::class);
5870
$this->stripTagsMock = $this->createMock(StripTags::class);
5971
$this->testConnection = $this->objectManager->getObject(
6072
TestConnection::class,
6173
[
6274
'client' => $this->clientMock,
6375
'resultJsonFactory' => $this->resultJsonFactoryMock,
64-
'tagFilter' => $this->stripTagsMock
76+
'tagFilter' => $this->stripTagsMock,
77+
'context' => $context
6578
]
6679
);
6780
}
@@ -71,6 +84,9 @@ protected function setUp(): void
7184
*/
7285
public function testExecute(): void
7386
{
87+
$this->request->expects($this->once())
88+
->method('getParams')
89+
->willReturn(['api_key' => 'the_api_key']);
7490
$this->clientMock->expects($this->once())
7591
->method('testConnection')
7692
->willReturn(true);
@@ -95,6 +111,9 @@ public function testExecute(): void
95111
*/
96112
public function testExecuteWithError(): void
97113
{
114+
$this->request->expects($this->once())
115+
->method('getParams')
116+
->willReturn(['api_key' => 'the_api_key']);
98117
$this->clientMock->expects($this->once())
99118
->method('testConnection')
100119
->willReturn(false);

0 commit comments

Comments
 (0)