-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(messaging): separate queue testing
- Loading branch information
Showing
3 changed files
with
118 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
use Bow\Cache\CacheConfiguration; | ||
use Bow\Configuration\EnvConfiguration; | ||
use Bow\Configuration\LoggerConfiguration; | ||
use Bow\Mail\Envelop; | ||
use Bow\Mail\MailConfiguration; | ||
use Bow\Mail\MailQueueProducer; | ||
use Bow\Queue\Connection as QueueConnection; | ||
|
@@ -32,10 +33,10 @@ public static function setUpBeforeClass(): void | |
|
||
public function testQueueMail() | ||
{ | ||
$message = new Message(); | ||
$message->to("[email protected]"); | ||
$message->subject("hello from bow"); | ||
$producer = new MailQueueProducer("email", [], $message); | ||
$envelop = new Envelop(); | ||
$envelop->to("[email protected]"); | ||
$envelop->subject("hello from bow"); | ||
$producer = new MailQueueProducer("email", [], $envelop); | ||
|
||
$adapter = static::$connection->setConnection("beanstalkd")->getAdapter(); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
<?php | ||
|
||
namespace Bow\Tests\Queue; | ||
|
||
use Bow\Database\Barry\Model; | ||
use Bow\Messaging\MessagingQueueProducer; | ||
use Bow\Queue\Connection as QueueConnection; | ||
use Bow\Tests\Messaging\Stubs\TestMessage; | ||
use Bow\Tests\Messaging\Stubs\TestNotifiableModel; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class MessagingTest extends TestCase | ||
{ | ||
private static QueueConnection $queueConnection; | ||
private MockObject|Model $context; | ||
private MockObject|TestMessage $message; | ||
|
||
public static function setUpBeforeClass(): void | ||
{ | ||
parent::setUpBeforeClass(); | ||
|
||
// Initialize queue connection | ||
static::$queueConnection = new QueueConnection([ | ||
'default' => 'sync', | ||
'connections' => [ | ||
'sync' => [ | ||
'driver' => 'sync' | ||
] | ||
] | ||
]); | ||
} | ||
|
||
public function test_can_send_message_synchronously(): void | ||
{ | ||
$this->message->expects($this->once()) | ||
->method('process') | ||
->with($this->context); | ||
|
||
$this->context->sendMessage($this->message); | ||
} | ||
|
||
public function test_can_send_message_to_queue(): void | ||
{ | ||
$producer = new MessagingQueueProducer($this->context, $this->message); | ||
|
||
// Verify that the producer is created with correct parameters | ||
$this->assertInstanceOf(MessagingQueueProducer::class, $producer); | ||
|
||
// Push to queue and verify | ||
static::$queueConnection->getAdapter()->push($producer); | ||
|
||
$this->context->setMessageQueue($this->message); | ||
} | ||
|
||
public function test_can_send_message_to_specific_queue(): void | ||
{ | ||
$queue = 'high-priority'; | ||
$producer = new MessagingQueueProducer($this->context, $this->message); | ||
|
||
// Verify that the producer is created with correct parameters | ||
$this->assertInstanceOf(MessagingQueueProducer::class, $producer); | ||
|
||
// Push to specific queue and verify | ||
$adapter = static::$queueConnection->getAdapter(); | ||
$adapter->setQueue($queue); | ||
$adapter->push($producer); | ||
|
||
$this->context->sendMessageQueueOn($queue, $this->message); | ||
} | ||
|
||
public function test_can_send_message_with_delay(): void | ||
{ | ||
$delay = 3600; | ||
$producer = new MessagingQueueProducer($this->context, $this->message); | ||
|
||
// Verify that the producer is created with correct parameters | ||
$this->assertInstanceOf(MessagingQueueProducer::class, $producer); | ||
|
||
// Push to queue and verify | ||
$adapter = static::$queueConnection->getAdapter(); | ||
$adapter->setSleep($delay); | ||
$adapter->push($producer); | ||
|
||
$this->context->sendMessageLater($delay, $this->message); | ||
} | ||
|
||
public function test_can_send_message_with_delay_on_specific_queue(): void | ||
{ | ||
$delay = 3600; | ||
$queue = 'delayed-notifications'; | ||
$producer = new MessagingQueueProducer($this->context, $this->message); | ||
|
||
// Verify that the producer is created with correct parameters | ||
$this->assertInstanceOf(MessagingQueueProducer::class, $producer); | ||
|
||
// Push to specific queue with delay and verify | ||
$adapter = static::$queueConnection->getAdapter(); | ||
$adapter->setQueue($queue); | ||
$adapter->setSleep($delay); | ||
$adapter->push($producer); | ||
|
||
$this->context->sendMessageLaterOn($delay, $queue, $this->message); | ||
} | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->context = $this->createMock(TestNotifiableModel::class); | ||
$this->message = $this->createMock(TestMessage::class); | ||
} | ||
} |