You are here

public function ResourceServersTest::testExceptions in Auth0 Single Sign On 8.2

Test that exceptions are thrown for specific methods in specific cases.

Return value

void

Throws

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

File

vendor/auth0/auth0-php/tests/API/Management/ResourceServersTest.php, line 211

Class

ResourceServersTest
Class ResourceServersTest.

Namespace

Auth0\Tests\API\Management

Code

public function testExceptions() {

  // Test that the get method throws an exception if the $id parameter is empty.
  $caught_get_no_id_exception = false;
  try {
    self::$api
      ->get(null);
    usleep(AUTH0_PHP_TEST_INTEGRATION_SLEEP);
  } catch (CoreException $e) {
    $caught_get_no_id_exception = $this
      ->errorHasString($e, 'Invalid "id" parameter');
  }
  $this
    ->assertTrue($caught_get_no_id_exception);

  // Test that the delete method throws an exception if the $id parameter is empty.
  $caught_delete_no_id_exception = false;
  try {
    self::$api
      ->delete(null);
    usleep(AUTH0_PHP_TEST_INTEGRATION_SLEEP);
  } catch (CoreException $e) {
    $caught_delete_no_id_exception = $this
      ->errorHasString($e, 'Invalid "id" parameter');
  }
  $this
    ->assertTrue($caught_delete_no_id_exception);

  // Test that the update method throws an exception if the $id parameter is empty.
  $caught_update_no_id_exception = false;
  try {
    self::$api
      ->update(null, []);
    usleep(AUTH0_PHP_TEST_INTEGRATION_SLEEP);
  } catch (CoreException $e) {
    $caught_update_no_id_exception = $this
      ->errorHasString($e, 'Invalid "id" parameter');
  }
  $this
    ->assertTrue($caught_update_no_id_exception);

  // Test that the create method throws an exception if the $identifier parameter is empty.
  $caught_create_empty_identifier_param_exception = false;
  try {
    self::$api
      ->create(null, []);
    usleep(AUTH0_PHP_TEST_INTEGRATION_SLEEP);
  } catch (CoreException $e) {
    $caught_create_empty_identifier_param_exception = $this
      ->errorHasString($e, 'Invalid "identifier" field');
  }
  $this
    ->assertTrue($caught_create_empty_identifier_param_exception);
  $caught_create_invalid_identifier_field_exception = false;
  try {
    self::$api
      ->create('identifier', [
      'identifier' => 1234,
    ]);
    usleep(AUTH0_PHP_TEST_INTEGRATION_SLEEP);
  } catch (CoreException $e) {
    $caught_create_invalid_identifier_field_exception = $this
      ->errorHasString($e, 'Invalid "identifier" field');
  }
  $this
    ->assertTrue($caught_create_invalid_identifier_field_exception);
}