- Implement Bird API client (`bird.php`) for handling HTTP requests to Bird services. - Add routes for voice and flash call management (`birdVoiceFlashCallsRoute.php`, `birdNumbersRoute.php`). - Introduce test cases for voice calls, flash calls, and numbers (`VoiceCallsApiTest.php`, `NumbersAndFlashCallsApiTest.php`). - Include configuration management classes and APIs for enabling the Bird module and managing API keys (`bird_c.php`). - Provide OpenAPI specifications for flash call endpoints (`bird-flash-calls.md`).
51 lines
2.8 KiB
PHP
51 lines
2.8 KiB
PHP
<?php
|
|
// Define app root for direct CLI execution
|
|
if (!defined('WD')) {
|
|
define('WD', dirname(__DIR__, 2));
|
|
}
|
|
|
|
require_once WD . '/classes/bird.php';
|
|
|
|
function ok($message): void { echo "\n\033[32m✔ $message\033[0m\n"; }
|
|
function fail($message): void { echo "\n\033[31m✖ $message\033[0m\n"; }
|
|
|
|
// Minimal fakes to avoid DB and network
|
|
class FakeBoolVar { private bool $v; public function __construct(bool $v){$this->v=$v;} public function isTrue(): bool { return $this->v; } public function getVariableValue(): string { return $this->v ? 'true' : 'false'; } }
|
|
class FakeStringVar { private string $v; public function __construct(string $v){$this->v=$v;} public function getVariableValue(): string { return $this->v; } }
|
|
class FakeBirdConfig { public $enabled; public $api_key; public $server_url; }
|
|
|
|
class TestBird extends \classes\bird {
|
|
public function __construct(bool $enabled, string $api_key, string $server_url)
|
|
{
|
|
// Do not call parent constructor to avoid DB access
|
|
$cfg = new FakeBirdConfig();
|
|
$cfg->enabled = new FakeBoolVar($enabled);
|
|
$cfg->api_key = new FakeStringVar($api_key);
|
|
$cfg->server_url = new FakeStringVar($server_url);
|
|
$this->config = $cfg;
|
|
}
|
|
|
|
protected function doHttpRequest(string $method, string $url, array $headers, string $body = ''): array
|
|
{
|
|
return ['status_code' => 200, 'body' => '{}'];
|
|
}
|
|
}
|
|
|
|
// Positive checks
|
|
$b = new TestBird(true, 'test_token_123', 'https://api.bird.com');
|
|
try { $b->requireModuleEnabled(); ok('Module enabled check passes when enabled=true'); } catch (\Exception $e) { fail('Module enabled should pass when enabled=true'); }
|
|
try { $b->requireValidApiKey(); ok('API key check passes when key provided'); } catch (\Exception $e) { fail('API key should be considered valid when provided'); }
|
|
try { $b->requireValidServerURL(); ok('Server URL check passes when URL provided'); } catch (\Exception $e) { fail('Server URL should be considered valid when provided'); }
|
|
|
|
// Negative checks
|
|
$thrown = false; try { (new TestBird(false, 'x', 'https://api.bird.com'))->requireModuleEnabled(); } catch (\Exception $e) { $thrown = true; }
|
|
if ($thrown) { ok('Module enabled guard throws when disabled'); } else { fail('Module enabled guard should throw when disabled'); }
|
|
|
|
$thrown = false; try { (new TestBird(true, '', 'https://api.bird.com'))->requireValidApiKey(); } catch (\Exception $e) { $thrown = true; }
|
|
if ($thrown) { ok('API key guard throws when key is empty'); } else { fail('API key guard should throw when key is empty'); }
|
|
|
|
$thrown = false; try { (new TestBird(true, 'x', ''))->requireValidServerURL(); } catch (\Exception $e) { $thrown = true; }
|
|
if ($thrown) { ok('Server URL guard throws when URL is empty'); } else { fail('Server URL guard should throw when URL is empty'); }
|
|
|
|
echo "\nBirdConfigTest completed.\n";
|