Public Access
b73c1eba25
Generic: Repo Health / Scripts governance (push) Has been cancelled
Generic: Repo Health / Repository health (push) Has been cancelled
Generic: Repo Health / Report Issues (push) Has been cancelled
Generic: Project CI / Tests (pull_request) Has been cancelled
Platform: mokoplatform CI / Gate 2: Unit Tests (8.1) (pull_request) Has been cancelled
Platform: mokoplatform CI / Gate 2: Unit Tests (8.2) (pull_request) Has been cancelled
Platform: mokoplatform CI / Gate 2: Unit Tests (8.3) (pull_request) Has been cancelled
Platform: mokoplatform CI / Gate 3: Self-Health Check (pull_request) Has been cancelled
Platform: mokoplatform CI / Gate 4: Governance (pull_request) Has been cancelled
Platform: mokoplatform CI / Gate 5: Template Integrity (pull_request) Has been cancelled
Platform: mokoplatform CI / CI Summary (pull_request) Has been cancelled
Universal: PR Check / Build RC Package (pull_request) Has been cancelled
Universal: PR Check / Report Issues (pull_request) Has been cancelled
Generic: Repo Health / Scripts governance (pull_request) Has been cancelled
Generic: Repo Health / Repository health (pull_request) Has been cancelled
Generic: Repo Health / Report Issues (pull_request) Has been cancelled
Generic: Repo Health / Site Health (push) Has been cancelled
Generic: Repo Health / Access control (push) Has been cancelled
Generic: Repo Health / Site Health (pull_request) Has been cancelled
Universal: PR Check / Branch Policy (pull_request) Has been cancelled
Generic: Repo Health / Access control (pull_request) Has been cancelled
Universal: Build & Release / Promote to RC (pull_request) Has been cancelled
RC Revert / Rename rc/ back to dev/ (pull_request) Has been cancelled
Universal: Security Audit / Dependency Audit (pull_request) Has been cancelled
Branch Cleanup / Delete merged branch (pull_request) Has been cancelled
Universal: Secret Scanning / Gitleaks Secret Scan (pull_request) Has been cancelled
Universal: PR Check / Validate PR (pull_request) Has been cancelled
Universal: Build & Release / Build & Release Pipeline (pull_request) Has been cancelled
Generic: Project CI / Lint & Validate (pull_request) Has been cancelled
Platform: mokoplatform CI / Gate 1: Code Quality (pull_request) Has been cancelled
Scans source files to detect platform, name, version, element_name, package_type, language, entry_point, description, and license_spdx. Supports Joomla, Dolibarr, Go, MCP/Node, and generic platforms. Includes --diff and --update modes for comparing against and pushing to the Gitea manifest API. Warns on missing core fields. Also removes deprecated mcp/servers/mokowaas_api (consolidated to separate repo) and syncs dev branch changes.
96 lines
2.8 KiB
PHP
96 lines
2.8 KiB
PHP
#!/usr/bin/env php
|
|
<?php
|
|
/* Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
|
|
*
|
|
* This file is part of a Moko Consulting project.
|
|
*
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
*
|
|
* FILE INFORMATION
|
|
* DEFGROUP: MokoPlatform.Tests
|
|
* INGROUP: MokoPlatform
|
|
* REPO: https://git.mokoconsulting.tech/MokoConsulting/mokoplatform
|
|
* PATH: /tests/test_circuit_breaker_handling.php
|
|
* BRIEF: Circuit breaker handling tests
|
|
*/
|
|
|
|
/**
|
|
* Test circuit breaker exception handling in bulk sync
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
require_once __DIR__ . '/../vendor/autoload.php';
|
|
|
|
use MokoEnterprise\{
|
|
ApiClient,
|
|
CircuitBreakerOpen,
|
|
RateLimitExceeded
|
|
};
|
|
|
|
echo "Testing Circuit Breaker Exception Handling\n";
|
|
echo str_repeat('=', 60) . "\n\n";
|
|
|
|
// Test 1: Verify CircuitBreakerOpen exception can be caught
|
|
echo "1. Testing CircuitBreakerOpen exception...\n";
|
|
try {
|
|
throw new CircuitBreakerOpen("Circuit breaker is open. Service unavailable.");
|
|
} catch (CircuitBreakerOpen $e) {
|
|
echo " ✓ CircuitBreakerOpen exception caught: {$e->getMessage()}\n";
|
|
}
|
|
|
|
// Test 2: Verify RateLimitExceeded exception can be caught
|
|
echo "\n2. Testing RateLimitExceeded exception...\n";
|
|
try {
|
|
throw new RateLimitExceeded("Rate limit exceeded. Wait 60 seconds.");
|
|
} catch (RateLimitExceeded $e) {
|
|
echo " ✓ RateLimitExceeded exception caught: {$e->getMessage()}\n";
|
|
}
|
|
|
|
// Test 3: Test circuit breaker with ApiClient
|
|
echo "\n3. Testing ApiClient circuit breaker...\n";
|
|
$client = new ApiClient(
|
|
baseUrl: 'https://api.github.com',
|
|
authToken: 'fake_token_for_testing',
|
|
circuitBreakerThreshold: 2, // Low threshold for testing
|
|
circuitBreakerTimeout: 5
|
|
);
|
|
|
|
// Simulate failures to trip the circuit breaker
|
|
echo " Simulating failures to trip circuit breaker...\n";
|
|
for ($i = 1; $i <= 3; $i++) {
|
|
try {
|
|
// This will fail due to invalid token
|
|
$client->get('/user');
|
|
} catch (\Exception $e) {
|
|
echo " - Attempt {$i}: " . get_class($e) . "\n";
|
|
}
|
|
}
|
|
|
|
// Check circuit state
|
|
$state = $client->getCircuitState();
|
|
echo " Circuit breaker state: {$state}\n";
|
|
|
|
if ($state === 'OPEN') {
|
|
echo " ✓ Circuit breaker correctly opened after failures\n";
|
|
} else {
|
|
echo " ⚠️ Circuit breaker state: {$state} (expected OPEN)\n";
|
|
}
|
|
|
|
// Test 4: Verify multi-catch syntax works (PHP 7.1+)
|
|
echo "\n4. Testing multi-catch syntax...\n";
|
|
try {
|
|
$random = rand(0, 1);
|
|
if ($random === 0) {
|
|
throw new CircuitBreakerOpen("Test circuit breaker");
|
|
} else {
|
|
throw new RateLimitExceeded("Test rate limit");
|
|
}
|
|
} catch (CircuitBreakerOpen | RateLimitExceeded $e) {
|
|
echo " ✓ Multi-catch works: " . get_class($e) . "\n";
|
|
}
|
|
|
|
echo "\n" . str_repeat('=', 60) . "\n";
|
|
echo "✓ All Circuit Breaker Exception Handling Tests Passed!\n";
|
|
echo str_repeat('=', 60) . "\n";
|