You are here

public function RestClientTest::testObjects in Salesforce Suite 8.4

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

@covers ::objects

File

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

Class

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

Namespace

Drupal\Tests\salesforce\Unit

Code

public function testObjects() {
  $this
    ->initClient(array_merge($this->methods, [
    'apiCall',
  ]));
  $objects = [
    'sobjects' => [
      'Test' => [
        'name' => 'Test',
        'updateable' => TRUE,
      ],
      'NonUpdateable' => [
        'name' => 'NonUpdateable',
        'updateable' => FALSE,
      ],
    ],
  ];
  $cache = (object) [
    'created' => time(),
    'data' => $objects,
  ];
  unset($cache->data['sobjects']['NonUpdateable']);
  $this->cache
    ->expects($this
    ->at(0))
    ->method('get')
    ->willReturn($cache);
  $this->cache
    ->expects($this
    ->at(1))
    ->method('get')
    ->willReturn(FALSE);
  $this->client
    ->expects($this
    ->once())
    ->method('apiCall')
    ->willReturn($objects);

  // First call, from cache:
  $this
    ->assertEquals($cache->data['sobjects'], $this->client
    ->objects());

  // Second call, from apiCall()
  $this
    ->assertEquals($cache->data['sobjects'], $this->client
    ->objects());
}