Files
michaelschiemer/tests/debug/test-campaign-discovery.php
Michael Schiemer 5050c7d73a docs: consolidate documentation into organized structure
- Move 12 markdown files from root to docs/ subdirectories
- Organize documentation by category:
  • docs/troubleshooting/ (1 file)  - Technical troubleshooting guides
  • docs/deployment/      (4 files) - Deployment and security documentation
  • docs/guides/          (3 files) - Feature-specific guides
  • docs/planning/        (4 files) - Planning and improvement proposals

Root directory cleanup:
- Reduced from 16 to 4 markdown files in root
- Only essential project files remain:
  • CLAUDE.md (AI instructions)
  • README.md (Main project readme)
  • CLEANUP_PLAN.md (Current cleanup plan)
  • SRC_STRUCTURE_IMPROVEMENTS.md (Structure improvements)

This improves:
 Documentation discoverability
 Logical organization by purpose
 Clean root directory
 Better maintainability
2025-10-05 11:05:04 +02:00

134 lines
4.4 KiB
PHP
Executable File

#!/usr/bin/env php
<?php
declare(strict_types=1);
require_once __DIR__ . '/../../vendor/autoload.php';
use App\Framework\Cache\Driver\InMemoryCache;
use App\Framework\Cache\GeneralCache;
use App\Framework\Core\PathProvider;
use App\Framework\DateTime\SystemClock;
use App\Framework\Discovery\Factory\DiscoveryServiceFactory;
use App\Framework\DI\DefaultContainer;
use App\Framework\Serializer\Php\PhpSerializer;
$basePath = realpath(__DIR__ . '/../..');
echo "=== Campaign Route Discovery Test ===" . PHP_EOL;
echo "Base path: {$basePath}" . PHP_EOL;
echo PHP_EOL;
// Create minimal dependencies
$pathProvider = new PathProvider($basePath);
$clock = new SystemClock();
$cacheDriver = new InMemoryCache();
$serializer = new PhpSerializer();
$cache = new GeneralCache($cacheDriver, $serializer);
// Create container
$container = new DefaultContainer();
// Create factory
$factory = new DiscoveryServiceFactory($container, $pathProvider, $cache, $clock);
// Create discovery service for development (no cache, full paths)
$discovery = $factory->createForDevelopment();
echo "Running discovery..." . PHP_EOL;
$startTime = microtime(true);
$registry = $discovery->discover();
$duration = round((microtime(true) - $startTime) * 1000, 2);
echo "Discovery completed in {$duration}ms" . PHP_EOL;
echo "Total items discovered: " . count($registry) . PHP_EOL;
echo "Files processed: " . $registry->getFileCount() . PHP_EOL;
echo PHP_EOL;
// Get all routes from AttributeRegistry
$routes = $registry->attributes->get(App\Framework\Attributes\Route::class);
echo "Total routes found: " . count($routes) . PHP_EOL;
echo PHP_EOL;
// Filter Campaign routes
echo "=== Looking for Campaign Routes ===" . PHP_EOL;
$campaignRoutes = [];
foreach ($routes as $attr) {
$className = $attr->className->toString();
if (str_contains($className, 'Campaign')) {
$campaignRoutes[] = $attr;
}
}
echo "Campaign routes found: " . count($campaignRoutes) . PHP_EOL;
echo PHP_EOL;
if (count($campaignRoutes) > 0) {
foreach ($campaignRoutes as $attr) {
echo "✅ Route found:" . PHP_EOL;
echo " Class: " . $attr->className->toString() . PHP_EOL;
echo " Method: " . $attr->methodName->toString() . PHP_EOL;
echo " Path: " . $attr->instance->path . PHP_EOL;
echo " HTTP Method: " . $attr->instance->method->value . PHP_EOL;
echo PHP_EOL;
}
} else {
echo "❌ NO CAMPAIGN ROUTES FOUND!" . PHP_EOL;
echo PHP_EOL;
// Debug: Show what was actually discovered
echo "=== All Discovered Routes (first 10) ===" . PHP_EOL;
$count = 0;
foreach ($routes as $attr) {
echo " " . $attr->className->toString() . "::" . $attr->methodName->toString() . PHP_EOL;
echo " Path: " . $attr->instance->path . PHP_EOL;
$count++;
if ($count >= 10) {
echo " ... and " . (count($routes) - 10) . " more" . PHP_EOL;
break;
}
}
}
// Specific check for PreSaveCampaign
echo PHP_EOL . "=== Specific PreSaveCampaign Check ===" . PHP_EOL;
$preSaveFound = false;
foreach ($routes as $attr) {
if ($attr->className->toString() === 'App\\Application\\Campaign\\PreSaveCampaign') {
$preSaveFound = true;
echo "✅ PreSaveCampaign found!" . PHP_EOL;
echo " Path: " . $attr->instance->path . PHP_EOL;
echo " Expected: /campaign/{slug}/presave/{platform}" . PHP_EOL;
break;
}
}
if (!$preSaveFound) {
echo "❌ PreSaveCampaign NOT found in discovery!" . PHP_EOL;
// Check if the file exists
$preSaveFile = $basePath . '/src/Application/Campaign/PreSaveCampaign.php';
echo PHP_EOL . "File exists: " . (file_exists($preSaveFile) ? 'yes' : 'no') . PHP_EOL;
echo "File readable: " . (is_readable($preSaveFile) ? 'yes' : 'no') . PHP_EOL;
// Try to load the class directly
if (class_exists('App\\Application\\Campaign\\PreSaveCampaign')) {
echo "Class can be loaded: yes" . PHP_EOL;
$reflection = new ReflectionClass('App\\Application\\Campaign\\PreSaveCampaign');
$method = $reflection->getMethod('__invoke');
$routeAttrs = $method->getAttributes(Route::class);
echo "Route attributes on __invoke method: " . count($routeAttrs) . PHP_EOL;
if (count($routeAttrs) > 0) {
echo "❌ Route attribute EXISTS but was NOT discovered!" . PHP_EOL;
echo "This indicates a problem with the discovery system!" . PHP_EOL;
}
}
}
echo PHP_EOL . "=== Test Complete ===" . PHP_EOL;