class RestClientTest in Salesforce Suite 8.3
Same name in this branch
- 8.3 tests/src/Unit/RestClientTest.php \Drupal\Tests\salesforce\Unit\RestClientTest
- 8.3 modules/salesforce_encrypt/tests/src/Unit/RestClientTest.php \Drupal\Tests\salesforce_encrypt\Unit\RestClientTest
@coversDefaultClass \Drupal\salesforce_encrypt\Rest\RestClient @group salesforce
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\salesforce_encrypt\Unit\RestClientTest
Expanded class hierarchy of RestClientTest
File
- modules/
salesforce_encrypt/ tests/ src/ Unit/ RestClientTest.php, line 22
Namespace
Drupal\Tests\salesforce_encrypt\UnitView source
class RestClientTest extends UnitTestCase {
public static $modules = [
'key',
'encrypt',
'salesforce',
'salesforce_encrypt',
];
protected $httpClient;
protected $configFactory;
protected $state;
protected $cache;
protected $json;
protected $time;
protected $encryption;
protected $profileManager;
protected $lock;
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$this->accessToken = 'foo';
$this->refreshToken = 'bar';
$this->identity = [
'zee' => 'bang',
];
$this->httpClient = $this
->getMock(Client::CLASS);
$this->configFactory = $this
->getMockBuilder(ConfigFactory::CLASS)
->disableOriginalConstructor()
->getMock();
$this->state = $this
->getMockBuilder(State::CLASS)
->disableOriginalConstructor()
->getMock();
$this->cache = $this
->createMock(CacheBackendInterface::CLASS);
$this->json = $this
->createMock('Drupal\\Component\\Serialization\\Json');
$this->encryption = $this
->createMock(EncryptServiceInterface::CLASS);
$this->profileManager = $this
->createMock(EncryptionProfileManagerInterface::CLASS);
$this->lock = $this
->createMock(LockBackendInterface::CLASS);
$this->encryptionProfile = $this
->createMock(EncryptionProfileInterface::CLASS);
$this->json = $this
->createMock(Json::CLASS);
$this->time = $this
->createMock(TimeInterface::CLASS);
$this->client = $this
->getMockBuilder(RestClient::CLASS)
->setMethods([
'doGetEncryptionProfile',
])
->setConstructorArgs([
$this->httpClient,
$this->configFactory,
$this->state,
$this->cache,
$this->json,
$this->time,
$this->encryption,
$this->profileManager,
$this->lock,
])
->getMock();
}
/**
* @covers ::encrypt
*
* encrypt is protected, so we get at it through ::getAccessToken
* This test covers the case where access token is NULL.
*/
public function testEncryptNull() {
// Test unencrypted.
$this->state
->expects($this
->any())
->method('get')
->willReturn(NULL);
$this->client
->expects($this
->any())
->method('doGetEncryptionProfile')
->willReturn(NULL);
$this
->assertFalse($this->client
->getAccessToken());
}
/**
* @covers ::encrypt
*
* This test covers the case where access token is not NULL.
*/
public function testEncryptNotNull() {
// Test unencrypted.
$this->state
->expects($this
->any())
->method('get')
->willReturn('not null');
$this->client
->expects($this
->any())
->method('doGetEncryptionProfile')
->willReturn($this->encryptionProfile);
$this->encryption
->expects($this
->any())
->method('decrypt')
->willReturn($this->accessToken);
$this
->assertEquals($this->accessToken, $this->client
->getAccessToken());
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
RestClientTest:: |
protected | property | ||
RestClientTest:: |
protected | property | ||
RestClientTest:: |
protected | property | ||
RestClientTest:: |
protected | property | ||
RestClientTest:: |
protected | property | ||
RestClientTest:: |
protected | property | ||
RestClientTest:: |
public static | property | ||
RestClientTest:: |
protected | property | ||
RestClientTest:: |
protected | property | ||
RestClientTest:: |
protected | property | ||
RestClientTest:: |
public | function |
Overrides UnitTestCase:: |
|
RestClientTest:: |
public | function | @covers ::encrypt | |
RestClientTest:: |
public | function | @covers ::encrypt | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |