Files
2026-09-15 10:35:56 +08:00

45 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
namespace Esun\LingxingErp\Test\Unit\Model\Api;
use Esun\LingxingErp\Model\Api\TokenProvider;
use Esun\LingxingErp\Model\Config;
use Magento\Framework\App\CacheInterface;
use Magento\Framework\HTTP\Client\Curl;
use Magento\Framework\HTTP\Client\CurlFactory;
use Magento\Framework\Lock\LockManagerInterface;
use PHPUnit\Framework\TestCase;
class TokenProviderTest extends TestCase
{
public function testAcceptsDocumentedHttpStyleBusinessCode(): void
{
$config = $this->createMock(Config::class);
$config->method('getApiBaseUrl')->willReturn('https://example.test');
$config->method('getAppId')->willReturn('app-id');
$config->method('getAppSecret')->willReturn('app-secret');
$cache = $this->createMock(CacheInterface::class);
$cache->method('load')->willReturn(false);
$cache->expects(self::once())->method('save');
$curl = $this->createMock(Curl::class);
$curl->method('getStatus')->willReturn(200);
$curl->method('getBody')->willReturn((string)json_encode([
'code' => '200',
'msg' => 'OK',
'data' => ['access_token' => 'token-value', 'expires_in' => 3600],
]));
$curlFactory = $this->createMock(CurlFactory::class);
$curlFactory->method('create')->willReturn($curl);
$lock = $this->createMock(LockManagerInterface::class);
$lock->method('lock')->willReturn(true);
$lock->expects(self::once())->method('unlock');
$provider = new TokenProvider($config, $cache, $curlFactory, $lock);
self::assertSame('token-value', $provider->getAccessToken());
}
}