1799401db5
Branch Policy Check / Verify merge target (pull_request) Successful in 1s
- Add Copyright + FILE INFORMATION headers to 11 PHP enterprise classes - Add FILE INFORMATION blocks to 9 PHP files with incomplete headers - Add headers to 2 test files - Add markdown comment headers to 27 index/README files - Add headers to 5 root markdown files - Add FILE INFORMATION to 4 files with existing but incomplete headers All files now conform to moko-platform file header standard. Authored-by: Moko Consulting Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
116 lines
3.7 KiB
PHP
116 lines
3.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/* 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: MokoStandards.Tests
|
|
* INGROUP: MokoStandards
|
|
* REPO: https://git.mokoconsulting.tech/MokoConsulting/moko-platform
|
|
* PATH: /tests/test_enterprise_libraries.php
|
|
* BRIEF: Enterprise library tests
|
|
*/
|
|
|
|
require_once __DIR__ . '/../../vendor/autoload.php';
|
|
|
|
use MokoEnterprise\MetricsCollector;
|
|
use MokoEnterprise\SecurityValidator;
|
|
use MokoEnterprise\Transaction;
|
|
use MokoEnterprise\TransactionManager;
|
|
use MokoEnterprise\UnifiedValidator;
|
|
use MokoEnterprise\PathValidatorPlugin;
|
|
use MokoEnterprise\CLIApp;
|
|
|
|
echo "Testing MokoStandards Enterprise Libraries\n";
|
|
echo str_repeat('=', 60) . "\n\n";
|
|
|
|
// Test 1: MetricsCollector
|
|
echo "1. Testing MetricsCollector...\n";
|
|
$metrics = new MetricsCollector('test_service');
|
|
$metrics->increment('requests_total');
|
|
$metrics->increment('requests_total', 3);
|
|
$metrics->setGauge('cpu_usage', 45.5);
|
|
$timer = $metrics->startTimer('operation');
|
|
usleep(100000); // 0.1 seconds
|
|
$timer->stop();
|
|
$counter = $metrics->getCounter('requests_total');
|
|
$gauge = $metrics->getGauge('cpu_usage');
|
|
echo " ✓ Counter: {$counter}, Gauge: {$gauge}\n";
|
|
echo " ✓ MetricsCollector v{$metrics->getVersion()} working!\n\n";
|
|
|
|
// Test 2: SecurityValidator
|
|
echo "2. Testing SecurityValidator...\n";
|
|
$validator = new SecurityValidator();
|
|
$testCode = 'password = "mysecret123"';
|
|
file_put_contents('/tmp/test_security.php', "<?php\n{$testCode}\n");
|
|
$findings = $validator->scanFile('/tmp/test_security.php');
|
|
echo " ✓ Found " . count($findings) . " security findings\n";
|
|
echo " ✓ SecurityValidator v{$validator->getVersion()} working!\n";
|
|
unlink('/tmp/test_security.php');
|
|
echo "\n";
|
|
|
|
// Test 3: TransactionManager
|
|
echo "3. Testing TransactionManager...\n";
|
|
$state = ['value' => 0];
|
|
$txn = new Transaction('test_transaction');
|
|
try {
|
|
$txn->execute('step1', function() use (&$state) {
|
|
$state['value'] += 10;
|
|
return $state['value'];
|
|
});
|
|
$txn->execute('step2', function() use (&$state) {
|
|
$state['value'] *= 2;
|
|
return $state['value'];
|
|
});
|
|
$txn->commit();
|
|
echo " ✓ Transaction committed. Final value: {$state['value']}\n";
|
|
} catch (Exception $e) {
|
|
echo " ✗ Transaction failed: {$e->getMessage()}\n";
|
|
}
|
|
|
|
$manager = new TransactionManager();
|
|
$stats = $manager->getStats();
|
|
echo " ✓ TransactionManager working!\n\n";
|
|
|
|
// Test 4: UnifiedValidation
|
|
echo "4. Testing UnifiedValidation...\n";
|
|
$unifiedValidator = new UnifiedValidator();
|
|
$unifiedValidator->addPlugin(new PathValidatorPlugin());
|
|
$context = ['paths' => ['/tmp', '/usr']];
|
|
$results = $unifiedValidator->validateAll($context);
|
|
echo " ✓ Ran " . count($results) . " validation(s)\n";
|
|
echo " ✓ All passed: " . ($unifiedValidator->allPassed() ? 'Yes' : 'No') . "\n";
|
|
echo " ✓ UnifiedValidator v{$unifiedValidator->getVersion()} working!\n\n";
|
|
|
|
// Test 5: CliFramework
|
|
echo "5. Testing CliFramework...\n";
|
|
|
|
class TestCLI extends CLIApp {
|
|
protected function setupArguments(): array {
|
|
return ['name:' => 'Name to greet'];
|
|
}
|
|
|
|
protected function run(): int {
|
|
$name = $this->getOption('name', 'World');
|
|
echo " ✓ Hello, {$name}!\n";
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
// Simulate CLI arguments
|
|
$_SERVER['argv'] = ['test', '--name=MokoStandards', '--quiet'];
|
|
$app = new TestCLI('test_cli', 'Test CLI App');
|
|
$exitCode = $app->execute();
|
|
echo " ✓ Exit code: {$exitCode}\n";
|
|
echo " ✓ CliFramework v{$app->getVersion()} working!\n\n";
|
|
|
|
echo str_repeat('=', 60) . "\n";
|
|
echo "✓ All 5 Enterprise Libraries Tested Successfully!\n";
|
|
echo "Library Migration: 100% Complete (10/10)\n";
|
|
echo str_repeat('=', 60) . "\n";
|