Skip to content

Commit c2c8a24

Browse files
committed
Works on code coverage
1 parent 25a6964 commit c2c8a24

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

tests/TestCase/TestSuite/QueueTestSuiteTest.php

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44
namespace Cake\Queue\Test\TestCase\TestSuite;
55

66
use Cake\Queue\QueueManager;
7+
use Cake\Queue\TestSuite\Constraint\Queue\JobQueued;
78
use Cake\Queue\TestSuite\QueueTrait as TestQueueTrait;
89
use Cake\Queue\TestSuite\TestQueueClient;
10+
use Cake\Queue\TestSuite\Transport\TestConsumer;
911
use Cake\Queue\TestSuite\Transport\TestContext;
12+
use Cake\Queue\TestSuite\Transport\TestDestination;
1013
use Cake\TestSuite\TestCase;
1114
use Enqueue\Client\MessagePriority;
15+
use Interop\Queue\Topic;
1216
use PHPUnit\Framework\AssertionFailedError;
1317
use TestApp\Job\LogToDebugJob;
1418

@@ -598,4 +602,92 @@ public function testJobCapturedWithProducerDelayAndTtl(): void
598602
$this->assertEquals(10, $jobs[0]['options']['expires']);
599603
$this->assertEquals(3, $jobs[0]['options']['priority']);
600604
}
605+
606+
/**
607+
* Test extractMessageBody with args fallback
608+
*
609+
* @return void
610+
*/
611+
public function testExtractMessageBodyWithArgs(): void
612+
{
613+
$body = json_encode([
614+
'class' => [LogToDebugJob::class],
615+
'args' => [['test' => 'value']],
616+
]);
617+
618+
$context = new TestContext();
619+
$destination = $context->createQueue('default');
620+
$message = $context->createMessage($body);
621+
622+
TestQueueClient::captureMessage($destination, $message);
623+
624+
$jobs = $this->getQueuedJobs();
625+
$this->assertEquals(['test' => 'value'], $jobs[0]['data']);
626+
}
627+
628+
/**
629+
* Test extractMessageBody with invalid JSON
630+
*
631+
* @return void
632+
*/
633+
public function testExtractMessageBodyWithInvalidJson(): void
634+
{
635+
$context = new TestContext();
636+
$destination = $context->createQueue('default');
637+
$message = $context->createMessage('invalid json');
638+
639+
TestQueueClient::captureMessage($destination, $message);
640+
641+
$jobs = $this->getQueuedJobs();
642+
$this->assertNull($jobs[0]['jobClass']);
643+
}
644+
645+
/**
646+
* Test createConsumer with other destination
647+
*
648+
* @return void
649+
*/
650+
public function testCreateConsumerWithOtherDestination(): void
651+
{
652+
$context = new TestContext();
653+
$destination = new TestDestination('test');
654+
655+
$consumer = $context->createConsumer($destination);
656+
657+
$this->assertInstanceOf(TestConsumer::class, $consumer);
658+
}
659+
660+
/**
661+
* Test createConsumer with Topic destination (not Queue)
662+
*
663+
* @return void
664+
*/
665+
public function testCreateConsumerWithTopicOnlyDestination(): void
666+
{
667+
$context = new TestContext();
668+
$topic = $this->createMock(Topic::class);
669+
$topic->method('getTopicName')->willReturn('test-topic');
670+
671+
$consumer = $context->createConsumer($topic);
672+
673+
$this->assertInstanceOf(TestConsumer::class, $consumer);
674+
}
675+
676+
/**
677+
* Test QueueConstraintBase with at parameter
678+
*
679+
* @return void
680+
*/
681+
public function testQueueConstraintBaseWithAt(): void
682+
{
683+
QueueManager::push(LogToDebugJob::class, []);
684+
QueueManager::push(LogToDebugJob::class, []);
685+
686+
$constraint = new JobQueued(0);
687+
$this->assertTrue($constraint->matches(LogToDebugJob::class));
688+
$this->assertEquals('job #0 was queued', $constraint->toString());
689+
690+
$constraint = new JobQueued(99);
691+
$this->assertFalse($constraint->matches(LogToDebugJob::class));
692+
}
601693
}

0 commit comments

Comments
 (0)