Skip to content

Commit

Permalink
Merge pull request #16 from magento-lynx/MC-40572
Browse files Browse the repository at this point in the history
MC-40572: Stabilize Unit tests (ASI)
  • Loading branch information
svera authored Feb 24, 2021
2 parents ae116dc + 7a32b0e commit 8bf4e43
Showing 1 changed file with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

use Magento\AdobeStockAdminUi\Controller\Adminhtml\System\Config\TestConnection;
use Magento\AdobeStockClientApi\Api\ClientInterface;
use Magento\Backend\App\Action\Context;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Controller\Result\Json;
use Magento\Framework\Controller\Result\JsonFactory;
use Magento\Framework\Filter\StripTags;
Expand Down Expand Up @@ -42,6 +44,11 @@ class TestConnectionTest extends TestCase
*/
private $stripTagsMock;

/**
* @var RequestInterface|MockObject
*/
private $request;

/**
* @var TestConnection
*/
Expand All @@ -53,15 +60,21 @@ class TestConnectionTest extends TestCase
protected function setUp(): void
{
$this->objectManager = new ObjectManager($this);
$this->clientMock = $this->getMockForAbstractClass(ClientInterface::class);
$context = $this->createMock(Context::class);
$this->request = $this->createMock(RequestInterface::class);
$context->expects($this->once())
->method('getRequest')
->willReturn($this->request);
$this->clientMock = $this->createMock(ClientInterface::class);
$this->resultJsonFactoryMock = $this->createMock(JsonFactory::class);
$this->stripTagsMock = $this->createMock(StripTags::class);
$this->testConnection = $this->objectManager->getObject(
TestConnection::class,
[
'client' => $this->clientMock,
'resultJsonFactory' => $this->resultJsonFactoryMock,
'tagFilter' => $this->stripTagsMock
'tagFilter' => $this->stripTagsMock,
'context' => $context
]
);
}
Expand All @@ -71,6 +84,9 @@ protected function setUp(): void
*/
public function testExecute(): void
{
$this->request->expects($this->once())
->method('getParams')
->willReturn(['api_key' => 'the_api_key']);
$this->clientMock->expects($this->once())
->method('testConnection')
->willReturn(true);
Expand All @@ -95,6 +111,9 @@ public function testExecute(): void
*/
public function testExecuteWithError(): void
{
$this->request->expects($this->once())
->method('getParams')
->willReturn(['api_key' => 'the_api_key']);
$this->clientMock->expects($this->once())
->method('testConnection')
->willReturn(false);
Expand Down

0 comments on commit 8bf4e43

Please sign in to comment.