Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"test": "SHELL_INTERACTIVE=1 vendor/bin/phpunit --colors=always --verbose ",
"test-ci": "vendor/bin/phpunit --coverage-text --coverage-clover=build/coverage.xml",
"phpcs": "SHELL_INTERACTIVE=1 ./vendor/bin/phpcs --standard=phpcs-ruleset.xml -s",
"phpcbf": "SHELL_INTERACTIVE=1 ./vendor/bin/phpcbf --standard=phpcs-ruleset.xml .",
"phpcbf": "./vendor/bin/phpcbf --standard=phpcs-ruleset.xml .",
"phpcbf-path": "SHELL_INTERACTIVE=1 ./vendor/bin/phpcbf --standard=phpcs-ruleset.xml",
"sniffs": "./vendor/bin/phpcs --standard=phpcs-ruleset.xml -e"
}
}
15 changes: 11 additions & 4 deletions phpcs-ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
<exclude name="Generic.Files.EndFileNoNewline"/>
<exclude name="Generic.Files.LowercasedFilename"/>
</rule>
<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="120"/>
<property name="absoluteLineLimit" value="120"/>
</properties>
</rule>
<rule ref="Generic.Formatting">
<exclude name="Generic.Formatting.NoSpaceAfterCast"/>
</rule>
Expand All @@ -51,6 +57,7 @@
<rule ref="Squiz.Classes"/>
<rule ref="Squiz.Commenting">
<exclude name="Squiz.Commenting.ClosingDeclarationComment"/>
<exclude name="Squiz.Commenting.ClassComment.TagNotAllowed"/>
<exclude name="Squiz.Commenting.FileComment"/>
<exclude name="Squiz.Commenting.LongConditionClosingComment"/>
<exclude name="Squiz.Commenting.FunctionComment.ScalarTypeHintMissing"/>
Expand All @@ -61,7 +68,7 @@
</rule>
<rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing">
<properties>
<property name="equalsSpacing" value="1" />
<property name="equalsSpacing" value="1"/>
</properties>
</rule>
<rule ref="Squiz.Operators">
Expand All @@ -78,9 +85,9 @@
</rule>
<rule ref="Squiz.WhiteSpace.FunctionSpacing">
<properties>
<property name="spacing" value="1" />
<property name="spacingBeforeFirst" value="0" />
<property name="spacingAfterLast" value="0" />
<property name="spacing" value="1"/>
<property name="spacingBeforeFirst" value="0"/>
<property name="spacingAfterLast" value="0"/>
</properties>
</rule>
</ruleset>
48 changes: 33 additions & 15 deletions src/API/Management/Logs.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,52 @@

namespace Auth0\SDK\API\Management;

/**
* Class Logs.
* Access to the v2 Management API Logs endpoint.
*
* @package Auth0\SDK\API\Management
*/
class Logs extends GenericResource
{
/**
* Get a single Log event.
* Required scope: "read:logs"
*
* @param string $log_id Log entry ID to get.
*
* @param string $id
* @return mixed
*
* @throws \Exception Thrown by Guzzle for API errors.
*
* @link https://auth0.com/docs/api/management/v2#!/Logs/get_logs_by_id
*/
public function get($id)
public function get($log_id)
{
return $this->apiClient->get()
->logs($id)
->call();
return $this->apiClient->method('get')
->addPath('logs', $log_id)
->call();
}

/**
* Retrieves log entries that match the specified search criteria (or list all entries if no criteria is used).
* Required scope: "read:logs"
*
* @param array $params Log search parameters to send:
* - Including a restricted "fields" parameter can speed up API calls significantly.
* - Results are paged by default; pass a "page" and "per_page" param to adjust what results are shown.
*
* @param array $params
* @return mixed
*
* @throws \Exception Thrown by Guzzle for API errors.
*
* @link https://auth0.com/docs/api/management/v2#!/Logs/get_logs
*/
public function search($params = [])
public function search(array $params = [])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the array word doing here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type hinting, will throw an error if an array is not passed in.

{
$client = $this->apiClient->get()
->logs();

foreach ($params as $param => $value) {
$client->withParam($param, $value);
}

return $client->call();
return $this->apiClient->method('get')
->addPath('logs')
->withDictParams($params)
->call();
}
}
87 changes: 87 additions & 0 deletions tests/API/Management/LogsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

namespace Auth0\Tests\API;

use Auth0\SDK\API\Management;

/**
* Class LogsTest.
* Tests the Auth0\SDK\API\Management\Logs class.
*
* @package Auth0\Tests\API
*/
class LogsTest extends ApiTests
{

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

/**
* Sets up API client for entire testing class.
*
* @return void
*/
public static function setUpBeforeClass()
{
$env = self::getEnvStatic();
$token = self::getTokenStatic($env, [ 'logs' => [ 'actions' => ['read'] ] ]);
$api = new Management($token, $env['DOMAIN'], ['timeout' => 30]);

self::$api = $api->logs;
}

/**
* Test a general search.
*
* @return void
*/
public function testLogSearchAndGetById()
{
$search_results = self::$api->search([
'fields' => '_id,log_id,date',
'include_fields' => true,
]);
$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']);
$this->assertNotEmpty($one_log);
$this->assertEquals($search_results[0]['log_id'], $one_log['log_id']);
}

/**
* Test pagination parameters.
*
* @return void
*/
public function testLogSearchPagination()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand how this one is "testing pagination". It only does a request and asserts that the response size is 10 items (per_page). Is not like other tests you've made before where you first ask for the first page of 2 items, and then ask for the second page of 1 items and compare that call 1[1].id==call 2[0].id

{
$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,
]);

$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']);
}
}
8 changes: 4 additions & 4 deletions tests/API/Management/UsersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected function getCreateBody()
'email' => 'test-create-user-'.$this->rand.'@auth0.com',
'password' => 'Y6t82hQjpXCMd3oD7Zsc',
'picture' => 'https://cdn.auth0.com/styleguide/components/1.0.8/media/logos/img/badge.png',
'email_verified' => false,
'email_verified' => true,
'user_metadata' => [
'key1' => 'value1',
'key2' => 'value2',
Expand Down Expand Up @@ -116,7 +116,7 @@ protected function afterCreate($entity)
$expected = $this->getCreateBody();
$this->assertNotEmpty($this->getId($entity));
$this->assertEquals($expected['email'], $entity['email']);
$this->assertFalse($entity['email_verified']);
$this->assertTrue($entity['email_verified']);
$this->assertEquals($expected['user_metadata']['key1'], $entity['user_metadata']['key1']);
$this->assertEquals($expected['user_metadata']['key2'], $entity['user_metadata']['key2']);
}
Expand All @@ -130,7 +130,7 @@ protected function getUpdateBody()
{
return [
'email' => 'test-update-user-'.$this->rand.'@auth0.com',
'email_verified' => true,
'email_verified' => false,
'user_metadata' => [
'key1' => 'value4',
'key3' => 'value3',
Expand All @@ -147,7 +147,7 @@ protected function afterUpdate($entity)
{
$expected = $this->getUpdateBody();
$this->assertEquals($expected['email'], $entity['email']);
$this->assertTrue($entity['email_verified']);
$this->assertFalse($entity['email_verified']);
$this->assertEquals($expected['user_metadata']['key1'], $entity['user_metadata']['key1']);
$this->assertEquals($expected['user_metadata']['key3'], $entity['user_metadata']['key3']);
}
Expand Down