/** * @requires PHPUnit 5 */ public function testAutorizationFail() { $access_token = "fake access token"; $endpoint = getenv("SE_ENDPOINT_PROBLEMS"); $client = new ProblemsClientV3($access_token, $endpoint); $this->expectException(SphereEngineResponseException::class); $this->expectExceptionCode(401); $client->test(); }
public function testAutorizationFail() { $access_token = "fake access token"; $endpoint = getenv("SE_ENDPOINT_PROBLEMS"); $invalidClient = new ProblemsClientV3($access_token, $endpoint); try { $invalidClient->test(); $this->assertTrue(false); } catch (SphereEngineResponseException $e) { $this->assertTrue($e->getCode() == 401); } }
<?php /** * Example presents authorization error handling for * Sphere Engine Problems API client */ use SphereEngine\Api\ProblemsClientV3; use SphereEngine\Api\SphereEngineResponseException; // require library require_once '../../../autoload.php'; // define access parameters $accessToken = "wrong access token"; $endpoint = '<endpoint>'; $client = new ProblemsClientV3($accessToken, $endpoint); // initialization try { $client->test(); } catch (SphereEngineResponseException $e) { if ($e->getCode() == 401) { echo 'Invalid access token'; } }
<?php /** * Example presents usage of the successful test() API method */ use SphereEngine\Api\ProblemsClientV3; use SphereEngine\Api\SphereEngineResponseException; // require library require_once '../../autoload.php'; // define access parameters $accessToken = '<access_token>'; $endpoint = '<endpoint>'; // initialization $client = new ProblemsClientV3($accessToken, $endpoint); // API usage try { $response = $client->test(); } catch (SphereEngineResponseException $e) { if ($e->getCode() == 401) { echo 'Invalid access token'; } }