You are here

public function ClientGrantsTest::testCreateUpdateDeleteGrant in Auth0 Single Sign On 8.2

Test that we can create, update, and delete a Client Grant.

Return value

void

Throws

CoreException Thrown when there is a problem with parameters passed to the method.

\Exception Thrown by the Guzzle HTTP client when there is a problem with the API call.

File

vendor/auth0/auth0-php/tests/API/Management/ClientGrantsTest.php, line 170

Class

ClientGrantsTest
Class ClientGrantsTest. Tests the Auth0\SDK\API\Management\ClientGrants class.

Namespace

Auth0\Tests\API

Code

public function testCreateUpdateDeleteGrant() {
  $client_id = self::$env['APP_CLIENT_ID'];
  $audience = self::$apiIdentifier;

  // Create a Client Grant with just one of the testing scopes.
  $create_result = self::$api
    ->create($client_id, $audience, [
    self::$scopes[0],
  ]);
  usleep(AUTH0_PHP_TEST_INTEGRATION_SLEEP);
  $this
    ->assertArrayHasKey('id', $create_result);
  $this
    ->assertEquals($client_id, $create_result['client_id']);
  $this
    ->assertEquals($audience, $create_result['audience']);
  $this
    ->assertEquals([
    self::$scopes[0],
  ], $create_result['scope']);
  $grant_id = $create_result['id'];

  // Test patching the created Client Grant.
  $update_result = self::$api
    ->update($grant_id, self::$scopes);
  usleep(AUTH0_PHP_TEST_INTEGRATION_SLEEP);
  $this
    ->assertEquals(self::$scopes, $update_result['scope']);

  // Test deleting the created Client Grant.
  $delete_result = self::$api
    ->delete($grant_id);
  usleep(AUTH0_PHP_TEST_INTEGRATION_SLEEP);
  $this
    ->assertNull($delete_result);
}