Skip to content

Commit

Permalink
Additinal docs and testing for Grants
Browse files Browse the repository at this point in the history
  • Loading branch information
joshcanhelp committed Feb 25, 2019
1 parent ffbb272 commit 195190b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/API/Management/Grants.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class Grants extends GenericResource
{
/**
* Get all Grants by page.
* Get all Grants with pagination.
* Required scope: "read:grants"
*
* @param integer $page Page number to return, zero-based.
Expand All @@ -21,6 +21,8 @@ class Grants extends GenericResource
* @return mixed
*
* @throws \Exception Thrown by the HTTP client when there is a problem with the API call.
*
* @link https://auth0.com/docs/api/management/v2#!/Grants/get_grants
*/
public function getAll($page = 0, $per_page = null, array $params = [])
{
Expand All @@ -39,7 +41,7 @@ public function getAll($page = 0, $per_page = null, array $params = [])
}

/**
* Get Grants by Client ID.
* Get Grants by Client ID with pagination.
* Required scope: "read:grants"
*
* @param string $client_id Client ID to filter Grants.
Expand All @@ -50,6 +52,8 @@ public function getAll($page = 0, $per_page = null, array $params = [])
*
* @throws CoreException If $client_id is empty or not a string.
* @throws \Exception Thrown by the HTTP client when there is a problem with the API call.
*
* @link https://auth0.com/docs/api/management/v2#!/Grants/get_grants
*/
public function getByClientId($client_id, $page = 0, $per_page = null)
{
Expand All @@ -61,7 +65,7 @@ public function getByClientId($client_id, $page = 0, $per_page = null)
}

/**
* Get Grants by Audience.
* Get Grants by Audience with pagination.
* Required scope: "read:grants"
*
* @param string $audience Audience to filter Grants.
Expand All @@ -72,6 +76,8 @@ public function getByClientId($client_id, $page = 0, $per_page = null)
*
* @throws CoreException If $audience is empty or not a string.
* @throws \Exception Thrown by the HTTP client when there is a problem with the API call.
*
* @link https://auth0.com/docs/api/management/v2#!/Grants/get_grants
*/
public function getByAudience($audience, $page = null, $per_page = null)
{
Expand All @@ -83,7 +89,7 @@ public function getByAudience($audience, $page = null, $per_page = null)
}

/**
* Get Grants by User ID.
* Get Grants by User ID with pagination.
* Required scope: "read:grants"
*
* @param string $user_id User ID to filter Grants.
Expand All @@ -94,6 +100,8 @@ public function getByAudience($audience, $page = null, $per_page = null)
*
* @throws CoreException If $user_id is empty or not a string.
* @throws \Exception Thrown by the HTTP client when there is a problem with the API call.
*
* @link https://auth0.com/docs/api/management/v2#!/Grants/get_grants
*/
public function getByUserId($user_id, $page = 0, $per_page = null)
{
Expand All @@ -114,6 +122,8 @@ public function getByUserId($user_id, $page = 0, $per_page = null)
*
* @throws CoreException If $id is empty or not a string.
* @throws \Exception Thrown by the HTTP client when there is a problem with the API call.
*
* @link https://auth0.com/docs/api/management/v2#!/Grants/delete_grants_by_id
*/
public function delete($id)
{
Expand Down
36 changes: 36 additions & 0 deletions tests/API/Management/GrantsTestMocked.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,15 @@ public function testThatGrantsGetByClientIdThrowsException()
}

$this->assertTrue( $caught_exception );

try {
$caught_exception = false;
$api->grants->getByClientId( [ '__not_empty__' ] );
} catch (CoreException $e) {
$caught_exception = $this->errorHasString( $e, 'Empty or invalid "client_id" parameter' );
}

$this->assertTrue( $caught_exception );
}

/**
Expand Down Expand Up @@ -220,6 +229,15 @@ public function testThatGrantsGetByAudienceThrowsException()
}

$this->assertTrue( $caught_exception );

try {
$caught_exception = false;
$api->grants->getByAudience( [ '__not_empty__' ] );
} catch (CoreException $e) {
$caught_exception = $this->errorHasString( $e, 'Empty or invalid "audience" parameter' );
}

$this->assertTrue( $caught_exception );
}

/**
Expand Down Expand Up @@ -275,6 +293,15 @@ public function testThatGrantsGetByUserIdThrowsException()
}

$this->assertTrue( $caught_exception );

try {
$caught_exception = false;
$api->grants->getByUserId( [ '__not_empty__' ] );
} catch (CoreException $e) {
$caught_exception = $this->errorHasString( $e, 'Empty or invalid "user_id" parameter' );
}

$this->assertTrue( $caught_exception );
}

/**
Expand Down Expand Up @@ -319,5 +346,14 @@ public function testGrantsDeleteThrowsException()
}

$this->assertTrue( $caught_exception );

try {
$caught_exception = false;
$api->grants->delete( [ '__not_empty__' ] );
} catch (CoreException $e) {
$caught_exception = $this->errorHasString( $e, 'Empty or invalid "id" parameter' );
}

$this->assertTrue( $caught_exception );
}
}

0 comments on commit 195190b

Please sign in to comment.