You are here

public function RestClientTest::testObjectUpsert in Salesforce Suite 8.3

Same name and namespace in other branches
  1. 8.4 tests/src/Unit/RestClientTest.php \Drupal\Tests\salesforce\Unit\RestClientTest::testObjectUpsert()
  2. 5.0.x tests/src/Unit/RestClientTest.php \Drupal\Tests\salesforce\Unit\RestClientTest::testObjectUpsert()

@covers ::objectUpsert

File

tests/src/Unit/RestClientTest.php, line 314

Class

RestClientTest
@coversDefaultClass \Drupal\salesforce\Rest\RestClient @group salesforce

Namespace

Drupal\Tests\salesforce\Unit

Code

public function testObjectUpsert() {
  $this
    ->initClient(array_merge($this->methods, [
    'apiCall',
    'objectReadbyExternalId',
  ]));
  $createResponse = new RestResponse(new GuzzleResponse('200', [], json_encode([
    'id' => $this->salesforce_id,
  ])));
  $updateResponse = new RestResponse(new GuzzleResponse('204', [], ''));
  $sfid = new SFID($this->salesforce_id);
  $sobject = new SObject([
    'id' => $this->salesforce_id,
    'attributes' => [
      'type' => 'dummy',
    ],
  ]);
  $this->client
    ->expects($this
    ->at(0))
    ->method('apiCall')
    ->willReturn($createResponse);
  $this->client
    ->expects($this
    ->at(1))
    ->method('apiCall')
    ->willReturn($updateResponse);
  $this->client
    ->expects($this
    ->once())
    ->method('objectReadbyExternalId')
    ->willReturn($sobject);

  // Ensure both upsert-create and upsert-update return the same value.
  $this
    ->assertEquals($sfid, $this->client
    ->objectUpsert('', '', '', []));
  $this
    ->assertEquals($sfid, $this->client
    ->objectUpsert('', '', '', []));
}