createMock(ScopeConfigInterface::class); $scopeConfig->method('isSetFlag')->willReturn(true); $scopeConfig->method('getValue')->willReturnCallback( static function (string $path): string { return match (true) { str_ends_with($path, '/location') => 'global', str_ends_with($path, '/timeout') => '30', default => '', }; } ); $credentials = $this->createMock(Credentials::class); $credentials->method('get')->willReturn(['project_id' => 'test-project']); $accessToken = $this->createMock(AccessToken::class); $accessToken->method('get')->willReturn('test-token'); $curl = $this->createMock(Curl::class); $curl->expects(self::once())->method('post')->with( self::stringContains('test-project/locations/global:translateText'), self::callback(static function (string $payload): bool { $request = json_decode($payload, true); return $request['contents'] === ['Hello', 'world'] && $request['mimeType'] === 'text/html' && !str_contains($payload, '
Hello world
'; $result = $provider->translate([ 'content' => ['value' => $source, 'is_html' => true], ], 'en', 'fr'); self::assertSame( 'Bonjour monde
', $result['content'] ); } }