![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/magento/module-adobe-ims/Test/Unit/Model/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ declare(strict_types=1); namespace Magento\AdobeIms\Test\Unit\Model; use Magento\AdobeIms\Model\GetToken; use Magento\AdobeIms\Model\OAuth\TokenResponse; use Magento\AdobeImsApi\Api\ConfigInterface; use Magento\AdobeImsApi\Api\Data\TokenResponseInterfaceFactory; use Magento\Framework\HTTP\Client\Curl; use Magento\Framework\HTTP\Client\CurlFactory; use Magento\Framework\Serialize\Serializer\Json; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; /** * Get user token test */ class GetTokenTest extends TestCase { /** * @var ConfigInterface|MockObject */ private $configMock; /** * @var CurlFactory|MockObject */ private $curlFactoryMock; /** * @var Json|MockObject */ private $jsonMock; /** * @var TokenResponseInterfaceFactory|MockObject */ private $tokenResponseFactoryMock; /** * @var GetToken $getToken */ private $getToken; /** * Prepare test objects. */ protected function setUp(): void { $this->configMock = $this->createMock(ConfigInterface::class); $this->curlFactoryMock = $this->createMock(CurlFactory::class); $this->jsonMock = $this->createMock(Json::class); $this->tokenResponseFactoryMock = $this->createMock(TokenResponseInterfaceFactory::class); $this->getToken = new GetToken( $this->configMock, $this->curlFactoryMock, $this->jsonMock, $this->tokenResponseFactoryMock ); } /** * Test save. */ public function testExecute(): void { $curl = $this->createMock(Curl::class); $this->curlFactoryMock->expects($this->once()) ->method('create') ->willReturn($curl); $curl->expects($this->exactly(2)) ->method('addHeader') ->willReturn(null); $this->configMock->expects($this->once()) ->method('getTokenUrl') ->willReturn('http://www.some.url.com'); $this->configMock->expects($this->once()) ->method('getApiKey') ->willReturn('string'); $this->configMock->expects($this->once()) ->method('getPrivateKey') ->willReturn('string'); $curl->expects($this->once()) ->method('post') ->willReturn(null); $data = ['access_token' => 'string']; $this->jsonMock->expects($this->once()) ->method('unserialize') ->willReturn($data); $tokenResponse = $this->createMock(TokenResponse::class); $this->tokenResponseFactoryMock->expects($this->once()) ->method('create') ->with(['data' => $data]) ->willReturn($tokenResponse); $this->assertEquals($tokenResponse, $this->getToken->execute('code')); } }