You are here

public function ClientTest::testCheckProgress in Akamai 7.3

Tests the checkProgress method.

@covers Drupal\akamai\Ccu3Client::checkProgress

File

tests/Ccu3ClientTest.php, line 21
Unit tests for the Drupal\akamai\Ccu3Client class.

Class

ClientTest

Namespace

Drupal\akamai\Tests

Code

public function testCheckProgress() {
  $progress_uri = '/ccu/v2/purges/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx';

  // Create stub for response class.
  $response_stub = $this
    ->getMockBuilder('GuzzleHttp\\Psr7\\Response')
    ->disableOriginalConstructor()
    ->getMock();
  $response_stub
    ->method('getBody')
    ->willReturn('{
        "originalEstimatedSeconds": 480,
        "progressUri": "/ccu/v2/purges/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
        "originalQueueLength": 6,
        "purgeId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
        "supportId": "xxxxxxxxxxxxxxxxxxxx-xxxxxxxxx",
        "httpStatus": 200,
        "completionTime": null,
        "submittedBy": "test1",
        "purgeStatus": "In-Progress",
        "submissionTime": "2014-02-19T21:16:20Z",
        "pingAfterSeconds": 60
      }');

  // Create stub for the EdgeGrid client class.
  $edgegrid_client = $this
    ->getMockBuilder('\\Akamai\\Open\\EdgeGrid\\Client')
    ->disableOriginalConstructor()
    ->setMethods([
    'get',
  ])
    ->getMock();
  $edgegrid_client
    ->method('get')
    ->willReturn($response_stub);

  // Ensure that the `getBody` method of the response object is called.
  $response_stub
    ->expects($this
    ->once())
    ->method('getBody');

  // Ensure that the `get` method of the EdgeGrid client is called.
  $edgegrid_client
    ->expects($this
    ->once())
    ->method('get')
    ->with($this
    ->equalTo($progress_uri));
  $ccu_client = new Ccu3Client($edgegrid_client);
  $result = $ccu_client
    ->checkProgress($progress_uri);
  $this
    ->assertSame($result->progressUri, $progress_uri, 'Method checkProgress did not return decoded JSON response.');
}