Files
michaelschiemer/tests/debug/test-method-name-refactored.php
Michael Schiemer fc3d7e6357 feat(Production): Complete production deployment infrastructure
- Add comprehensive health check system with multiple endpoints
- Add Prometheus metrics endpoint
- Add production logging configurations (5 strategies)
- Add complete deployment documentation suite:
  * QUICKSTART.md - 30-minute deployment guide
  * DEPLOYMENT_CHECKLIST.md - Printable verification checklist
  * DEPLOYMENT_WORKFLOW.md - Complete deployment lifecycle
  * PRODUCTION_DEPLOYMENT.md - Comprehensive technical reference
  * production-logging.md - Logging configuration guide
  * ANSIBLE_DEPLOYMENT.md - Infrastructure as Code automation
  * README.md - Navigation hub
  * DEPLOYMENT_SUMMARY.md - Executive summary
- Add deployment scripts and automation
- Add DEPLOYMENT_PLAN.md - Concrete plan for immediate deployment
- Update README with production-ready features

All production infrastructure is now complete and ready for deployment.
2025-10-25 19:18:37 +02:00

192 lines
7.8 KiB
PHP

<?php
declare(strict_types=1);
require_once __DIR__ . '/../../vendor/autoload.php';
use App\Framework\Core\ValueObjects\ClassName;
use App\Framework\Core\ValueObjects\MethodName;
use App\Framework\Core\ValueObjects\QualifiedMethodName;
// Test class for method existence checks
class TestClass
{
public function publicMethod(): string
{
return 'public';
}
private function privateMethod(): string
{
return 'private';
}
public static function staticMethod(): string
{
return 'static';
}
public function __invoke(): string
{
return 'invoked';
}
}
echo "=== MethodName Refactoring Tests ===\n\n";
// Test 1: Basic MethodName creation
echo "Test 1: Basic MethodName creation\n";
$method = MethodName::create('getUserById');
echo "Method name: {$method->toString()}\n";
echo "Is magic method: " . ($method->isMagicMethod() ? 'yes' : 'no') . "\n";
echo "✓ Basic creation works\n\n";
// Test 2: Magic method factories
echo "Test 2: Magic method factories\n";
$construct = MethodName::construct();
$invoke = MethodName::invoke();
$toString = MethodName::toStringMagic();
$destruct = MethodName::destruct();
echo "Constructor: {$construct->toString()} - Is constructor: " . ($construct->isConstructor() ? 'yes' : 'no') . "\n";
echo "Invoke: {$invoke->toString()} - Is invokable: " . ($invoke->isInvokable() ? 'yes' : 'no') . "\n";
echo "ToString: {$toString->toString()} - Is toString: " . ($toString->isToString() ? 'yes' : 'no') . "\n";
echo "Destruct: {$destruct->toString()} - Is destructor: " . ($destruct->isDestructor() ? 'yes' : 'no') . "\n";
echo "✓ All magic method factories work\n\n";
// Test 3: Method existence checks
echo "Test 3: Method existence checks\n";
$className = ClassName::create(TestClass::class);
$publicMethod = MethodName::create('publicMethod');
$privateMethod = MethodName::create('privateMethod');
$staticMethod = MethodName::create('staticMethod');
$nonExistent = MethodName::create('nonExistentMethod');
echo "publicMethod exists: " . ($publicMethod->existsIn($className) ? 'yes' : 'no') . "\n";
echo "publicMethod is public: " . ($publicMethod->isPublicIn($className) ? 'yes' : 'no') . "\n";
echo "publicMethod is static: " . ($publicMethod->isStaticIn($className) ? 'yes' : 'no') . "\n";
echo "\n";
echo "privateMethod exists: " . ($privateMethod->existsIn($className) ? 'yes' : 'no') . "\n";
echo "privateMethod is public: " . ($privateMethod->isPublicIn($className) ? 'yes' : 'no') . "\n";
echo "\n";
echo "staticMethod exists: " . ($staticMethod->existsIn($className) ? 'yes' : 'no') . "\n";
echo "staticMethod is static: " . ($staticMethod->isStaticIn($className) ? 'yes' : 'no') . "\n";
echo "\n";
echo "nonExistentMethod exists: " . ($nonExistent->existsIn($className) ? 'yes' : 'no') . "\n";
echo "✓ Method existence checks work\n\n";
// Test 4: Reflection support
echo "Test 4: Reflection support\n";
$reflection = $publicMethod->getReflection($className);
if ($reflection !== null) {
echo "Got reflection for publicMethod\n";
echo "Method name: {$reflection->getName()}\n";
echo "Is public: " . ($reflection->isPublic() ? 'yes' : 'no') . "\n";
echo "Number of parameters: {$reflection->getNumberOfParameters()}\n";
echo "✓ Reflection works\n";
} else {
echo "✗ Failed to get reflection\n";
}
echo "\n";
// Test 5: QualifiedMethodName from string
echo "Test 5: QualifiedMethodName from string parsing\n";
$qualified = MethodName::fromQualified('TestClass::publicMethod');
echo "Qualified method: {$qualified->toString()}\n";
echo "Class name: {$qualified->className->getShortName()}\n";
echo "Method name: {$qualified->methodName->toString()}\n";
echo "Method exists: " . ($qualified->exists() ? 'yes' : 'no') . "\n";
echo "Method is public: " . ($qualified->isPublic() ? 'yes' : 'no') . "\n";
echo "✓ Qualified method parsing works\n\n";
// Test 6: QualifiedMethodName with ClassName
echo "Test 6: QualifiedMethodName with ClassName integration\n";
$qualified2 = MethodName::withClass($className, 'staticMethod');
echo "Qualified method: {$qualified2->toString()}\n";
echo "Fully qualified: {$qualified2->toFullyQualifiedString()}\n";
echo "Is static: " . ($qualified2->isStatic() ? 'yes' : 'no') . "\n";
echo "✓ ClassName integration works\n\n";
// Test 7: Method invocation via QualifiedMethodName
echo "Test 7: Method invocation\n";
$instance = new TestClass();
$qualified3 = QualifiedMethodName::fromString('TestClass::publicMethod');
$result = $qualified3->invoke($instance);
echo "Invoked publicMethod, result: {$result}\n";
$qualified4 = QualifiedMethodName::fromString('TestClass::staticMethod');
$result2 = $qualified4->invoke(null); // static method, no instance needed
echo "Invoked staticMethod, result: {$result2}\n";
$qualified5 = QualifiedMethodName::fromString('TestClass::__invoke');
$result3 = $qualified5->invoke($instance);
echo "Invoked __invoke magic method, result: {$result3}\n";
echo "✓ Method invocation works\n\n";
// Test 8: Pattern matching
echo "Test 8: Pattern matching\n";
$method1 = MethodName::create('getUserById');
$method2 = MethodName::create('getUserByEmail');
$method3 = MethodName::create('createUser');
echo "getUserById matches 'getUser*': " . ($method1->matches('getUser*') ? 'yes' : 'no') . "\n";
echo "getUserByEmail matches 'getUser*': " . ($method2->matches('getUser*') ? 'yes' : 'no') . "\n";
echo "createUser matches 'getUser*': " . ($method3->matches('getUser*') ? 'yes' : 'no') . "\n";
echo "getUserById matches '*By*': " . ($method1->matches('*By*') ? 'yes' : 'no') . "\n";
echo "✓ Pattern matching works\n\n";
// Test 9: Equality comparison
echo "Test 9: Equality comparison\n";
$method1 = MethodName::create('testMethod');
$method2 = MethodName::create('testMethod');
$method3 = MethodName::create('otherMethod');
echo "method1 equals method2: " . ($method1->equals($method2) ? 'yes' : 'no') . "\n";
echo "method1 equals method3: " . ($method1->equals($method3) ? 'yes' : 'no') . "\n";
$qualified1 = QualifiedMethodName::fromString('TestClass::publicMethod');
$qualified2 = QualifiedMethodName::fromString('TestClass::publicMethod');
$qualified3 = QualifiedMethodName::fromString('TestClass::privateMethod');
echo "qualified1 equals qualified2: " . ($qualified1->equals($qualified2) ? 'yes' : 'no') . "\n";
echo "qualified1 equals qualified3: " . ($qualified1->equals($qualified3) ? 'yes' : 'no') . "\n";
echo "✓ Equality comparison works\n\n";
// Performance test
echo "=== Performance Test ===\n";
$iterations = 10000;
// Test MethodName creation performance
$start = microtime(true);
for ($i = 0; $i < $iterations; $i++) {
$method = MethodName::create('testMethod');
}
$duration = microtime(true) - $start;
$avgPerOp = ($duration / $iterations) * 1000;
echo "MethodName::create() - {$iterations} iterations: " . number_format($duration * 1000, 2) . "ms\n";
echo "Average per operation: " . number_format($avgPerOp, 4) . "ms\n\n";
// Test QualifiedMethodName parsing performance
$start = microtime(true);
for ($i = 0; $i < $iterations; $i++) {
$qualified = MethodName::fromQualified('TestClass::publicMethod');
}
$duration = microtime(true) - $start;
$avgPerOp = ($duration / $iterations) * 1000;
echo "MethodName::fromQualified() - {$iterations} iterations: " . number_format($duration * 1000, 2) . "ms\n";
echo "Average per operation: " . number_format($avgPerOp, 4) . "ms\n\n";
// Test existence check performance
$className = ClassName::create(TestClass::class);
$method = MethodName::create('publicMethod');
$start = microtime(true);
for ($i = 0; $i < $iterations; $i++) {
$exists = $method->existsIn($className);
}
$duration = microtime(true) - $start;
$avgPerOp = ($duration / $iterations) * 1000;
echo "MethodName::existsIn() - {$iterations} iterations: " . number_format($duration * 1000, 2) . "ms\n";
echo "Average per operation: " . number_format($avgPerOp, 4) . "ms\n\n";
echo "=== All tests passed! ===\n";