InformationHeadersExtendTest.php in Auth0 Single Sign On 8.2
File
vendor/auth0/auth0-php/tests/API/Helpers/InformationHeadersExtendTest.php
View source
<?php
namespace Auth0\Tests\Api\Helpers;
use Auth0\Tests\API\Management\MockManagementApi;
use Auth0\Tests\API\Authentication\MockAuthenticationApi;
use Auth0\SDK\API\Helpers\InformationHeaders;
use Auth0\SDK\API\Helpers\ApiClient;
use GuzzleHttp\Psr7\Response;
class InformationHeadersExtendTest extends \PHPUnit_Framework_TestCase {
public static function tearDownAfterClass() {
$reset_headers = new InformationHeaders();
$reset_headers
->setCorePackage();
ApiClient::setInfoHeadersData($reset_headers);
parent::tearDownAfterClass();
}
public function testThatExtendedHeadersBuildCorrectly() {
$new_headers = self::setExtendedHeaders('test-extend-sdk-1', '1.2.3');
$new_headers
->setEnvironment('test-extend-env', '2.3.4');
$new_header_data = $new_headers
->get();
$this
->assertEquals('test-extend-sdk-1', $new_header_data['name']);
$this
->assertEquals('1.2.3', $new_header_data['version']);
$this
->assertArrayHasKey('env', $new_header_data);
$this
->assertArrayHasKey('php', $new_header_data['env']);
$this
->assertEquals(phpversion(), $new_header_data['env']['php']);
$this
->assertArrayHasKey('auth0-php', $new_header_data['env']);
$this
->assertEquals(ApiClient::API_VERSION, $new_header_data['env']['auth0-php']);
$this
->assertArrayHasKey('test-extend-env', $new_header_data['env']);
$this
->assertEquals('2.3.4', $new_header_data['env']['test-extend-env']);
}
public function testThatExtendedHeadersAreUsedForManagementApiCalls() {
$new_headers = self::setExtendedHeaders('test-extend-sdk-2', '2.3.4');
$api = new MockManagementApi([
new Response(200),
]);
$api
->call()->connections
->getAll();
$headers = $api
->getHistoryHeaders();
$this
->assertEquals($new_headers
->build(), $headers['Auth0-Client'][0]);
}
public function testThatExtendedHeadersAreUsedForAuthenticationApiCalls() {
$new_headers = self::setExtendedHeaders('test-extend-sdk-3', '3.4.5');
$api = new MockAuthenticationApi([
new Response(200),
]);
$api
->call()
->oauth_token([
'grant_type' => uniqid(),
]);
$headers = $api
->getHistoryHeaders();
$this
->assertEquals($new_headers
->build(), $headers['Auth0-Client'][0]);
}
public static function setExtendedHeaders($name, $version) {
$reset_headers = new InformationHeaders();
$reset_headers
->setCorePackage();
ApiClient::setInfoHeadersData($reset_headers);
$headers = ApiClient::getInfoHeadersData();
$new_headers = InformationHeaders::Extend($headers);
$new_headers
->setPackage($name, $version);
ApiClient::setInfoHeadersData($new_headers);
return $new_headers;
}
}