public function RestClientTest::testObjectDescribe in Salesforce Suite 8.4
Same name and namespace in other branches
- 8.3 tests/src/Unit/RestClientTest.php \Drupal\Tests\salesforce\Unit\RestClientTest::testObjectDescribe()
- 5.0.x tests/src/Unit/RestClientTest.php \Drupal\Tests\salesforce\Unit\RestClientTest::testObjectDescribe()
@covers ::objectDescribe
File
- tests/
src/ Unit/ RestClientTest.php, line 244
Class
- RestClientTest
- @coversDefaultClass \Drupal\salesforce\Rest\RestClient @group salesforce
Namespace
Drupal\Tests\salesforce\UnitCode
public function testObjectDescribe() {
$this
->initClient(array_merge($this->methods, [
'apiCall',
]));
$name = $this
->randomMachineName();
// @TODO this is fugly, do we need a refactor on RestResponse?
$restResponse = new RestResponse(new GuzzleResponse('200', [], json_encode([
'name' => $name,
'fields' => [
[
'name' => $this
->randomMachineName(),
'label' => 'Foo Bar',
$this
->randomMachineName() => $this
->randomMachineName(),
$this
->randomMachineName() => [
$this
->randomMachineName() => $this
->randomMachineName(),
$this
->randomMachineName() => $this
->randomMachineName(),
],
],
[
'name' => $this
->randomMachineName(),
],
],
])));
$this->client
->expects($this
->once())
->method('apiCall')
->willReturn($restResponse);
// Test that we hit "apiCall" and get expected result:
$result = $this->client
->objectDescribe($name);
$expected = new RestResponseDescribe($restResponse);
$this
->assertEquals($expected, $result);
// Test that cache gets set correctly:
$this->cache
->expects($this
->any())
->method('get')
->willReturn((object) [
'data' => $expected,
'created' => time(),
]);
// Test that we hit cache when we call again.
// (Otherwise, we'll blow the "once" condition)
$this
->assertEquals($expected, $this->client
->objectDescribe($name));
// @TODO what happens when we provide a name for non-existent SF table?
// 404 exception?
// Test that we throw an exception if name is not provided.
$this
->expectException(\Exception::class);
$this->client
->objectDescribe('');
}