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