99
1010use Magento \AdobeStockAdminUi \Controller \Adminhtml \System \Config \TestConnection ;
1111use Magento \AdobeStockClientApi \Api \ClientInterface ;
12+ use Magento \Backend \App \Action \Context ;
13+ use Magento \Framework \App \RequestInterface ;
1214use Magento \Framework \Controller \Result \Json ;
1315use Magento \Framework \Controller \Result \JsonFactory ;
1416use 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