62 lines
2.4 KiB
PHP
62 lines
2.4 KiB
PHP
<?php
|
|
// Live tests against the API with a sandbox_ key (writes are simulated, nothing is charged).
|
|
//
|
|
// TEST_API_KEY=sandbox_... TEST_DOMAIN=yourdomain.co.mz TEST_EMAIL_FROM=you@verified-domain \
|
|
// php tests/live.php
|
|
//
|
|
// TEST_API_URL points the tests to another server; leave it empty for the normal address.
|
|
// The key is never printed. A prod_ key is refused.
|
|
|
|
require __DIR__ . '/bootstrap.php';
|
|
|
|
use InterwebMz\Laravel\ApiException;
|
|
|
|
$key = getenv('TEST_API_KEY') ?: getenv(\InterwebMz\Laravel\Client::KEY_ENV);
|
|
if (!$key || strpos($key, 'sandbox_') !== 0) {
|
|
fwrite(STDERR, "Set TEST_API_KEY to a sandbox_ key.\n");
|
|
exit(2);
|
|
}
|
|
$c = new LiveClient(['api_key' => $key, 'mode' => 'sandbox', 'language' => 'en']);
|
|
|
|
$t = $c->token()['data'];
|
|
check('token: sandbox mode', $t['mode'] === 'sandbox' && $c->lastResponse()['mode'] === 'sandbox');
|
|
|
|
$w = $c->whois()->lookup('example.co.mz');
|
|
check('WHOIS answers', isset($w['data']['status']));
|
|
|
|
$a = $c->domains()->availability('free-name-' . date('YmdHis') . '.co.mz');
|
|
check('availability answers', isset($a['data']));
|
|
|
|
$domain = getenv('TEST_DOMAIN');
|
|
if ($domain) {
|
|
$records = $c->dns()->records($domain);
|
|
check('DNS zone read', is_array($records) && count($records) > 0);
|
|
$r = $c->dns()->upsert($domain, 'laravel-test', 'A', '192.0.2.44', 300);
|
|
check('DNS upsert simulated', $c->wasSimulated() && ($r['value'] ?? '') === '192.0.2.44');
|
|
}
|
|
|
|
try {
|
|
$s = $c->sms()->send('+258841234567', 'Test from the Laravel package.');
|
|
check('SMS simulated', $c->wasSimulated() && !empty($s['data']));
|
|
} catch (ApiException $e) {
|
|
check('SMS: ' . $e->getApiCode() . ' (' . $e->getMessage() . ')', in_array($e->getApiCode(), ['sms_not_active', 'forbidden'], true));
|
|
}
|
|
|
|
$from = getenv('TEST_EMAIL_FROM');
|
|
if ($from) {
|
|
try {
|
|
$m = $c->emailCenter()->send(['from' => $from, 'to' => 'ana@example.org', 'subject' => 'Test', 'text' => 'Test from the Laravel package.']);
|
|
check('email simulated', $c->wasSimulated() && !empty($m['data']));
|
|
} catch (ApiException $e) {
|
|
check('email: ' . $e->getApiCode() . ' (' . $e->getMessage() . ')', false);
|
|
}
|
|
}
|
|
|
|
try {
|
|
$c->get('/v1/domains/' . rawurlencode('not-on-this-account-' . date('His') . '.co.mz'));
|
|
check('unknown domain gives 404', false);
|
|
} catch (ApiException $e) {
|
|
check('unknown domain gives 404 not_found', $e->getStatus() === 404 && $e->getApiCode() === 'not_found' && $e->hint() !== '');
|
|
}
|
|
|
|
done();
|