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()); } }