You are here

public function ClientsTest::testIntegrationGetAllMethod in Auth0 Single Sign On 8.2

Throws

\Exception

File

vendor/auth0/auth0-php/tests/API/Management/ClientsTest.php, line 246

Class

ClientsTest
Class ClientsTest

Namespace

Auth0\Tests\API\Management

Code

public function testIntegrationGetAllMethod() {
  $env = self::getEnv();
  if (!$env['API_TOKEN']) {
    $this
      ->markTestSkipped('No client secret; integration test skipped');
  }
  $api = new Management($env['API_TOKEN'], $env['DOMAIN']);
  $fields = [
    'client_id',
    'tenant',
    'name',
    'app_type',
  ];
  $page_num = 3;

  // Get the second page of Clients with 1 per page (second result).
  $paged_results = $api
    ->clients()
    ->getAll($fields, true, $page_num, 1);
  usleep(AUTH0_PHP_TEST_INTEGRATION_SLEEP);

  // Make sure we only have one result, as requested.
  $this
    ->assertEquals(1, count($paged_results));

  // Make sure we only have the 6 fields we requested.
  $this
    ->assertEquals(count($fields), count($paged_results[0]));

  // Get many results (needs to include the created result if self::findCreatedItem === true).
  $many_results_per_page = 50;
  $many_results = $api
    ->clients()
    ->getAll($fields, true, 0, $many_results_per_page);
  usleep(AUTH0_PHP_TEST_INTEGRATION_SLEEP);

  // Make sure we have at least as many results as we requested.
  $this
    ->assertLessThanOrEqual($many_results_per_page, count($many_results));

  // Make sure our paged result above appears in the right place.
  // $page_num here represents the expected location for the single entity retrieved above.
  $this
    ->assertEquals($paged_results[0]['client_id'], $many_results[$page_num]['client_id']);
}