You are here

public function FileApiTest::testBadJsonFormatInErrorMessageSendRequest in TMGMT Translator Smartling 8.3

Same name and namespace in other branches
  1. 8.4 vendor/smartling/api-sdk-php/tests/unit/FileApiTest.php \Smartling\Tests\Unit\FileApiTest::testBadJsonFormatInErrorMessageSendRequest()
  2. 8.2 api-sdk-php/tests/unit/FileApiTest.php \Smartling\Tests\Unit\FileApiTest::testBadJsonFormatInErrorMessageSendRequest()
  3. 8.2 vendor/smartling/api-sdk-php/tests/unit/FileApiTest.php \Smartling\Tests\Unit\FileApiTest::testBadJsonFormatInErrorMessageSendRequest()

@covers \Smartling\File\FileApi::sendRequest @expectedException \Smartling\Exceptions\SmartlingApiException @expectedExceptionMessage Bad response format from Smartling

File

vendor/smartling/api-sdk-php/tests/unit/FileApiTest.php, line 688

Class

FileApiTest
Test class for Smartling\File\FileApi.

Namespace

Smartling\Tests\Unit

Code

public function testBadJsonFormatInErrorMessageSendRequest() {
  $this
    ->prepareClientResponseMock(false);
  $this->responseMock
    ->expects($this
    ->any())
    ->method('getStatusCode')
    ->willReturn(401);
  $this->responseMock
    ->expects($this
    ->any())
    ->method('getBody')
    ->willReturn(rtrim($this->responseWithException, '}'));
  $endpointUrl = vsprintf('%s/%s/context/html', [
    FileApi::ENDPOINT_URL,
    $this->projectId,
  ]);
  $this->client
    ->expects($this
    ->once())
    ->method('request')
    ->with('get', $endpointUrl, [
    'headers' => [
      'Accept' => 'application/json',
      'Authorization' => vsprintf('%s %s', [
        $this->authProvider
          ->getTokenType(),
        $this->authProvider
          ->getAccessToken(),
      ]),
    ],
    'exceptions' => false,
    'query' => [],
  ])
    ->willReturn($this->responseMock);
  $requestData = $this
    ->invokeMethod($this->object, 'getDefaultRequestData', [
    'query',
    [],
  ]);
  $this
    ->invokeMethod($this->object, 'setBaseUrl', [
    FileApi::ENDPOINT_URL . '/' . $this->projectId,
  ]);
  $this
    ->invokeMethod($this->object, 'sendRequest', [
    'context/html',
    $requestData,
    'get',
  ]);
}