/** * @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 error handling for createSubmission() API method */ use SphereEngine\Api\CompilersClientV3; // require library require_once '../../../autoload.php'; // define access parameters $accessToken = '<access_token>'; $endpoint = '<endpoint>'; // initialization $client = new CompilersClientV3($accessToken, $endpoint); // API usage $source = 'int main() { return 0; }'; $compiler = 11; // C language $input = '2016'; try { $response = $client->createSubmission($source, $compiler, $input); // response['id'] stores the ID of the created submission } catch (SphereEngineResponseException $e) { if ($e->getCode() == 401) { echo 'Invalid access token'; } }
<?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 getSubmission() API method */ use SphereEngine\Api\CompilersClientV3; // require library require_once '../../../autoload.php'; // define access parameters $accessToken = '<access_token>'; $endpoint = '<endpoint>'; // initialization $client = new CompilersClientV3($accessToken, $endpoint); // API usage $response = $client->getSubmission(2016);
<?php /** * Example presents usage of the successful getCompilers() API method */ use SphereEngine\Api\CompilersClientV3; // require library require_once '../../autoload.php'; // define access parameters $accessToken = '<access_token>'; $endpoint = '<endpoint>'; // initialization $client = new CompilersClientV3($accessToken, $endpoint); // API usage $response = $client->getCompilers();
<?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'; } }
<?php /** * Example presents error handling for getSubmission() 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 { $nonexisting_submission_id = 999999999; $response = $client->getSubmission($nonexisting_submission_id); } catch (SphereEngineResponseException $e) { if ($e->getCode() == 401) { echo 'Invalid access token'; } elseif ($e->getCode() == 404) { echo 'Submission does not exist'; } }
<?php /** * Example presents usage of the successful getSubmissionStream() API method */ use SphereEngine\Api\CompilersClientV3; // require library require_once '../../../autoload.php'; // define access parameters $accessToken = '<access_token>'; $endpoint = '<endpoint>'; // initialization $client = new CompilersClientV3($accessToken, $endpoint); // API usage $response = $client->getSubmissionStream(2016, 'output');
<?php /** * Example presents error handling for getSubmissionStream() 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 { $nonexisting_submission_id = 999999999; $response = $client->getSubmissionStream($nonexisting_submission_id, 'output'); } catch (SphereEngineResponseException $e) { if ($e->getCode() == 401) { echo 'Invalid access token'; } elseif ($e->getCode() == 404) { // aggregates two possible reasons of 404 error // non existing submission or stream echo 'Non existing resource (submission, stream), details available in the message: ' . $e->getMessage(); } }