class AkamaiClientV3Test in Akamai 8.3
@coversDefaultClass \Drupal\akamai\Plugin\Client\AkamaiClientV3
@group Akamai
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\akamai\Unit\AkamaiClientV3Test
Expanded class hierarchy of AkamaiClientV3Test
File
- tests/
src/ Unit/ AkamaiClientV3Test.php, line 15
Namespace
Drupal\Tests\akamai\UnitView source
class AkamaiClientV3Test extends UnitTestCase {
/**
* Creates a client to test.
*
* @param array $config
* An array of client configuration.
*
* @return \Drupal\akamai\Plugin\Client\AkamaiClientV3
* An AkamaiClient to test.
*/
protected function getClient(array $config = []) {
// Ensure some sane defaults.
$config = $config + [
'version' => 'v3',
'domain' => [
'production' => TRUE,
'staging' => FALSE,
],
'action_v3' => [
'delete' => TRUE,
'invalidate' => FALSE,
],
'basepath' => 'http://example.com',
'timeout' => 300,
'purge_urls_with_hostname' => FALSE,
];
$logger = $this
->prophesize(LoggerInterface::class)
->reveal();
$edgegridclient = $this
->getMockBuilder('Akamai\\Open\\EdgeGrid\\Client')
->disableOriginalConstructor()
->setMethods(NULL)
->getMock();
// Create stub for response class.
$response_stub = $this
->getMockBuilder('GuzzleHttp\\Psr7\\Response')
->disableOriginalConstructor()
->setMethods([
'getStatusCode',
])
->getMock();
$response_stub
->method('getStatusCode')
->willReturn(201);
// Create stub for the Akamai Client class.
return $this
->getMockBuilder('Drupal\\akamai\\Plugin\\Client\\AkamaiClientV3')
->setConstructorArgs([
[],
'v3',
[],
$edgegridclient,
$this
->getConfigFactoryStub([
'akamai.settings' => $config,
]),
$logger,
$this
->prophesize(MessengerInterface::class)
->reveal(),
$this
->prophesize(KeyProviderInterface::class)
->reveal(),
])
->setMethods([
'getQueueLength',
'purgeRequest',
])
->getMock();
}
/**
* Tests creation of a purge payload body.
*
* @covers ::createPurgeBody
*/
public function testCreatePurgeBody() {
$urls = [
'/node/11',
];
// URL type (default).
$expected = (object) [
'objects' => $urls,
];
$akamai_client = $this
->getClient();
$this
->assertEquals($expected, $akamai_client
->createPurgeBody($urls));
// URL type (default) with hostname setting enabled.
$expected = (object) [
'objects' => $urls,
'hostname' => 'http://example.com',
];
$akamai_client = $this
->getClient([
'purge_urls_with_hostname' => TRUE,
]);
$this
->assertEquals($expected, $akamai_client
->createPurgeBody($urls));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AkamaiClientV3Test:: |
protected | function | Creates a client to test. | |
AkamaiClientV3Test:: |
public | function | Tests creation of a purge payload body. | |
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. | |
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. | |
UnitTestCase:: |
protected | function | 340 |