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";