Files
michaelschiemer/tests/debug/test-redis-queue-basic.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

125 lines
4.5 KiB
PHP
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
declare(strict_types=1);
require_once __DIR__ . '/../bootstrap.php';
use App\Framework\Queue\InMemoryQueue;
use App\Framework\Queue\ValueObjects\JobPayload;
use App\Framework\Queue\ValueObjects\QueuePriority;
// Example Job Classes für Tests
class TestJob
{
public function __construct(
public string $id,
public string $description
) {}
}
echo "🔴 Testing RedisQueue Priority Logic (using InMemoryQueue)\n";
echo "========================================================\n\n";
echo " Note: Testing priority logic that will be used in RedisQueue\n";
echo " InMemoryQueue implements the same priority-based sorting\n\n";
// Test 1: Basic Priority Ordering
echo "1⃣ Testing Priority Ordering...\n";
$queue = new InMemoryQueue();
$lowJob = JobPayload::create(new TestJob('low', 'Low priority task'), QueuePriority::low());
$normalJob = JobPayload::create(new TestJob('normal', 'Normal priority task'), QueuePriority::normal());
$highJob = JobPayload::create(new TestJob('high', 'High priority task'), QueuePriority::high());
$criticalJob = JobPayload::create(new TestJob('critical', 'Critical task'), QueuePriority::critical());
// Push in random order
$queue->push($normalJob);
$queue->push($lowJob);
$queue->push($criticalJob);
$queue->push($highJob);
assert($queue->size() === 4, "❌ Queue should have 4 jobs");
// Should pop in priority order: critical > high > normal > low
$first = $queue->pop();
$second = $queue->pop();
$third = $queue->pop();
$fourth = $queue->pop();
assert($first !== null && $first->job->id === 'critical', "❌ First should be critical (got: " . ($first?->job->id ?? 'null') . ")");
assert($second !== null && $second->job->id === 'high', "❌ Second should be high (got: " . ($second?->job->id ?? 'null') . ")");
assert($third !== null && $third->job->id === 'normal', "❌ Third should be normal (got: " . ($third?->job->id ?? 'null') . ")");
assert($fourth !== null && $fourth->job->id === 'low', "❌ Fourth should be low (got: " . ($fourth?->job->id ?? 'null') . ")");
echo "✅ Priority ordering works correctly\n\n";
// Test 2: Queue Operations
echo "2⃣ Testing Queue Operations...\n";
$queue->clear();
assert($queue->size() === 0, "❌ Queue should be empty after clear");
$job1 = JobPayload::create(new TestJob('job1', 'First job'));
$job2 = JobPayload::create(new TestJob('job2', 'Second job'));
$queue->push($job1);
$queue->push($job2);
// Test peek
$peeked = $queue->peek();
assert($peeked !== null, "❌ Should peek a job");
assert($peeked->job->id === 'job1', "❌ Peeked job should be first job");
assert($queue->size() === 2, "❌ Queue size should not change after peek");
// Test pop
$popped = $queue->pop();
assert($popped !== null, "❌ Should pop a job");
assert($popped->job->id === 'job1', "❌ Popped job should be first job");
assert($queue->size() === 1, "❌ Queue size should decrease after pop");
echo "✅ Queue operations work correctly\n\n";
// Test 3: Statistics
echo "3⃣ Testing Queue Statistics...\n";
$queue->clear();
$highPriorityJob = JobPayload::create(new TestJob('stats1', 'Stats test'), QueuePriority::high());
$normalPriorityJob = JobPayload::create(new TestJob('stats2', 'Stats test'), QueuePriority::normal());
$queue->push($highPriorityJob);
$queue->push($normalPriorityJob);
$stats = $queue->getStats();
assert(isset($stats['total_items']), "❌ Stats should include total_items");
assert($stats['total_items'] === 2, "❌ Stats should show 2 total items");
assert(isset($stats['priority_breakdown']), "❌ Stats should include priority breakdown");
$breakdown = $stats['priority_breakdown'];
assert(isset($breakdown['high']), "❌ Should have high priority breakdown");
assert(isset($breakdown['normal']), "❌ Should have normal priority breakdown");
assert($breakdown['high'] === 1, "❌ Should have 1 high priority job");
assert($breakdown['normal'] === 1, "❌ Should have 1 normal priority job");
echo "✅ Queue statistics work correctly\n\n";
// Test 4: Empty Queue Handling
echo "4⃣ Testing Empty Queue Handling...\n";
$queue->clear();
$nullJob = $queue->pop();
assert($nullJob === null, "❌ Pop from empty queue should return null");
$nullPeek = $queue->peek();
assert($nullPeek === null, "❌ Peek at empty queue should return null");
assert($queue->size() === 0, "❌ Empty queue size should be 0");
echo "✅ Empty queue handling works correctly\n\n";
echo "🎉 ALL REDIS QUEUE LOGIC TESTS PASSED!\n";
echo "✨ Priority-based queue logic is working correctly!\n";
echo " RedisQueue implementation uses the same priority logic with Redis sorted sets.\n";