You are here

class LogsTest in Auth0 Single Sign On 8.2

Class LogsTest. Tests the Auth0\SDK\API\Management\Logs class.

@package Auth0\Tests\API

Hierarchy

Expanded class hierarchy of LogsTest

File

vendor/auth0/auth0-php/tests/API/Management/LogsTest.php, line 13

Namespace

Auth0\Tests\API
View source
class LogsTest extends ApiTests {

  /**
   * Logs API client.
   *
   * @var mixed
   */
  protected static $api;

  /**
   * Sets up API client for entire testing class.
   *
   * @return void
   *
   * @throws \Auth0\SDK\Exception\ApiException
   */
  public static function setUpBeforeClass() {
    $env = self::getEnv();
    $api = new Management($env['API_TOKEN'], $env['DOMAIN'], [
      'timeout' => 30,
    ]);
    self::$api = $api
      ->logs();
  }
  public function testThatMethodAndPropertyReturnSameClass() {
    $api = new Management(uniqid(), uniqid());
    $this
      ->assertInstanceOf(Management\Logs::class, $api->logs);
    $this
      ->assertInstanceOf(Management\Logs::class, $api
      ->logs());
    $api->logs = null;
    $this
      ->assertInstanceOf(Management\Logs::class, $api
      ->logs());
  }

  /**
   * Test a general search.
   *
   * @return void
   */
  public function testLogSearchAndGetById() {
    $search_results = self::$api
      ->search([
      'fields' => '_id,log_id,date',
      'include_fields' => true,
    ]);
    usleep(AUTH0_PHP_TEST_INTEGRATION_SLEEP);
    $this
      ->assertNotEmpty($search_results);
    $this
      ->assertNotEmpty($search_results[0]['_id']);
    $this
      ->assertNotEmpty($search_results[0]['log_id']);
    $this
      ->assertNotEmpty($search_results[0]['date']);
    $this
      ->assertCount(3, $search_results[0]);

    // Test getting a single log result with a valid ID from above.
    $one_log = self::$api
      ->get($search_results[0]['log_id']);
    usleep(AUTH0_PHP_TEST_INTEGRATION_SLEEP);
    $this
      ->assertNotEmpty($one_log);
    $this
      ->assertEquals($search_results[0]['log_id'], $one_log['log_id']);
  }

  /**
   * Test pagination parameters.
   *
   * @return void
   */
  public function testLogSearchPagination() {
    $expected_count = 5;
    $search_results = self::$api
      ->search([
      // Fields here to speed up API call.
      'fields' => '_id,log_id',
      'include_fields' => true,
      // Second page of 5 results.
      'page' => 1,
      'per_page' => $expected_count,
      // Include totals to check pagination.
      'include_totals' => true,
    ]);
    usleep(AUTH0_PHP_TEST_INTEGRATION_SLEEP);
    $this
      ->assertCount($expected_count, $search_results['logs']);
    $this
      ->assertEquals($expected_count, $search_results['length']);

    // Starting on 2nd page so starting result should be equal to the number per page.
    $this
      ->assertEquals($expected_count, $search_results['start']);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ApiTests::$env protected static property Environment variables.
ApiTests::getEnv protected static function Get all test suite environment variables.
ErrorHelpers::errorHasString protected function Does an error message contain a specific string?
LogsTest::$api protected static property Logs API client.
LogsTest::setUpBeforeClass public static function Sets up API client for entire testing class.
LogsTest::testLogSearchAndGetById public function Test a general search.
LogsTest::testLogSearchPagination public function Test pagination parameters.
LogsTest::testThatMethodAndPropertyReturnSameClass public function