Skip to content

Commit

Permalink
Add lazy-load Management methods
Browse files Browse the repository at this point in the history
  • Loading branch information
joshcanhelp committed Sep 18, 2019
1 parent 5a7a39f commit 0f59682
Show file tree
Hide file tree
Showing 13 changed files with 382 additions and 13 deletions.
266 changes: 266 additions & 0 deletions src/API/Management.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,272 @@ public function __construct($token, $domain, $guzzleOptions = [], $returnType =
$this->usersByEmail = new UsersByEmail($this->apiClient);
}

/**
* Return an instance of the Blacklists class.
*
* @return Blacklists
*/
public function blacklists()
{
if (! $this->blacklists instanceof Blacklists) {
$this->blacklists = new Blacklists($this->apiClient);
}

return $this->blacklists;
}

/**
* Return an instance of the Clients class.
*
* @return Clients
*/
public function clients()
{
if (! $this->clients instanceof Clients) {
$this->clients = new Clients($this->apiClient);
}

return $this->clients;
}

/**
* Return an instance of the ClientGrants class.
*
* @return ClientGrants
*/
public function clientGrants()
{
if (! $this->client_grants instanceof ClientGrants) {
$this->client_grants = new ClientGrants($this->apiClient);
}

return $this->client_grants;
}

/**
* Return an instance of the Connections class.
*
* @return Connections
*/
public function connections()
{
if (! $this->connections instanceof Connections) {
$this->connections = new Connections($this->apiClient);
}

return $this->connections;
}

/**
* Return an instance of the DeviceCredentials class.
*
* @return DeviceCredentials
*/
public function deviceCredentials()
{
if (! $this->deviceCredentials instanceof DeviceCredentials) {
$this->deviceCredentials = new DeviceCredentials($this->apiClient);
}

return $this->deviceCredentials;
}

/**
* Return an instance of the Emails class.
*
* @return Emails
*/
public function emails()
{
if (! $this->emails instanceof Emails) {
$this->emails = new Emails($this->apiClient);
}

return $this->emails;
}

/**
* Return an instance of the EmailTemplates class.
*
* @return EmailTemplates
*/
public function emailTemplates()
{
if (! $this->emailTemplates instanceof EmailTemplates) {
$this->emailTemplates = new EmailTemplates($this->apiClient);
}

return $this->emailTemplates;
}

/**
* Return an instance of the Grants class.
*
* @return Grants
*/
public function grants()
{
if (! $this->grants instanceof Grants) {
$this->grants = new Grants($this->apiClient);
}

return $this->grants;
}

/**
* Return an instance of the Jobs class.
*
* @return Jobs
*/
public function jobs()
{
if (! $this->jobs instanceof Jobs) {
$this->jobs = new Jobs($this->apiClient);
}

return $this->jobs;
}

/**
* Return an instance of the Logs class.
*
* @return Logs
*/
public function logs()
{
if (! $this->logs instanceof Logs) {
$this->logs = new Logs($this->apiClient);
}

return $this->logs;
}

/**
* Return an instance of the Roles class.
*
* @return Roles
*/
public function roles()
{
if (! $this->roles instanceof Roles) {
$this->roles = new Roles($this->apiClient);
}

return $this->roles;
}

/**
* Return an instance of the Rules class.
*
* @return Rules
*/
public function rules()
{
if (! $this->rules instanceof Rules) {
$this->rules = new Rules($this->apiClient);
}

return $this->rules;
}

/**
* Return an instance of the ResourceServers class.
*
* @return ResourceServers
*/
public function resourceServers()
{
if (! $this->resource_servers instanceof ResourceServers) {
$this->resource_servers = new ResourceServers($this->apiClient);
}

return $this->resource_servers;
}

/**
* Return an instance of the Stats class.
*
* @return Stats
*/
public function stats()
{
if (! $this->stats instanceof Stats) {
$this->stats = new Stats($this->apiClient);
}

return $this->stats;
}

/**
* Return an instance of the Tenants class.
*
* @return Tenants
*/
public function tenants()
{
if (! $this->tenants instanceof Tenants) {
$this->tenants = new Tenants($this->apiClient);
}

return $this->tenants;
}

/**
* Return an instance of the Tickets class.
*
* @return Tickets
*/
public function tickets()
{
if (! $this->tickets instanceof Tickets) {
$this->tickets = new Tickets($this->apiClient);
}

return $this->tickets;
}

/**
* Return an instance of the UserBlocks class.
*
* @return UserBlocks
*/
public function userBlocks()
{
if (! $this->userBlocks instanceof UserBlocks) {
$this->userBlocks = new UserBlocks($this->apiClient);
}

return $this->userBlocks;
}

/**
* Return an instance of the Users class.
*
* @return Users
*/
public function users()
{
if (! $this->users instanceof Users) {
$this->users = new Users($this->apiClient);
}

return $this->users;
}

/**
* Return an instance of the UsersByEmail class.
*
* @return UsersByEmail
*/
public function usersByEmail()
{
if (! $this->usersByEmail instanceof UsersByEmail) {
$this->usersByEmail = new UsersByEmail($this->apiClient);
}

return $this->usersByEmail;
}

protected function setApiClient()
{
$apiDomain = "https://{$this->domain}";
Expand Down
9 changes: 9 additions & 0 deletions tests/API/Management/BlacklistsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ public function testThatBlacklistRequestIsFormedProperly()
$this->assertEquals( 'application/json', $headers['Content-Type'][0] );
}

public function testThatMethodAndPropertyReturnSameClass()
{
$api = new Management(uniqid(), uniqid());
$this->assertInstanceOf( Management\Blacklists::class, $api->blacklists );
$this->assertInstanceOf( Management\Blacklists::class, $api->blacklists() );
$api->blacklists = null;
$this->assertInstanceOf( Management\Blacklists::class, $api->blacklists() );
}

/**
* @throws \Auth0\SDK\Exception\ApiException
*/
Expand Down
10 changes: 9 additions & 1 deletion tests/API/Management/ClientGrantsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,15 @@ public static function setUpBeforeClass()
public function setUp()
{
parent::setUp();
sleep(2);
}

public function testThatMethodAndPropertyReturnSameClass()
{
$api = new Management(uniqid(), uniqid());
$this->assertInstanceOf( Management\ClientGrants::class, $api->client_grants );
$this->assertInstanceOf( Management\ClientGrants::class, $api->clientGrants() );
$api->client_grants = null;
$this->assertInstanceOf( Management\ClientGrants::class, $api->clientGrants() );
}


Expand Down
9 changes: 9 additions & 0 deletions tests/API/Management/ClientsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ public function setUp()
sleep(2);
}

public function testThatMethodAndPropertyReturnSameClass()
{
$api = new Management(uniqid(), uniqid());
$this->assertInstanceOf( Management\Clients::class, $api->clients );
$this->assertInstanceOf( Management\Clients::class, $api->clients() );
$api->clients = null;
$this->assertInstanceOf( Management\Clients::class, $api->clients() );
}

/**
* Return the Clients API to test.
*
Expand Down
12 changes: 10 additions & 2 deletions tests/API/Management/ConnectionsMockedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
namespace Auth0\Tests\API\Management;

use Auth0\Tests\Traits\ErrorHelpers;

use Auth0\SDK\API\Helpers\InformationHeaders;

use Auth0\SDK\API\Management;
use GuzzleHttp\Psr7\Response;

/**
Expand Down Expand Up @@ -41,6 +40,15 @@ public static function setUpBeforeClass()
self::$expectedTelemetry = $infoHeadersData->build();
}

public function testThatMethodAndPropertyReturnSameClass()
{
$api = new Management(uniqid(), uniqid());
$this->assertInstanceOf( Management\Connections::class, $api->connections );
$this->assertInstanceOf( Management\Connections::class, $api->connections() );
$api->connections = null;
$this->assertInstanceOf( Management\Connections::class, $api->connections() );
}

/**
* Test a basic getAll connection call.
*
Expand Down
Loading

0 comments on commit 0f59682

Please sign in to comment.