33namespace Bow \Tests \Queue ;
44
55use Bow \Database \Barry \Model ;
6+ use Bow \Mail \MailConfiguration ;
7+ use Bow \View \ViewConfiguration ;
8+ use PHPUnit \Framework \TestCase ;
9+ use Bow \Cache \CacheConfiguration ;
10+ use Bow \Queue \QueueConfiguration ;
11+ use Bow \Configuration \EnvConfiguration ;
612use Bow \Messaging \MessagingQueueProducer ;
7- use Bow \Queue \Connection as QueueConnection ;
13+ use Bow \Configuration \LoggerConfiguration ;
14+ use Bow \Tests \Config \TestingConfiguration ;
815use Bow \Tests \Messaging \Stubs \TestMessage ;
9- use Bow \Tests \ Messaging \ Stubs \ TestNotifiableModel ;
16+ use Bow \Queue \ Connection as QueueConnection ;
1017use PHPUnit \Framework \MockObject \MockObject ;
11- use PHPUnit \ Framework \ TestCase ;
18+ use Bow \ Tests \ Messaging \ Stubs \ TestNotifiableModel ;
1219
1320class MessagingTest extends TestCase
1421{
15- private static QueueConnection $ queueConnection ;
22+ private static QueueConnection $ connection ;
1623 private MockObject |Model $ context ;
1724 private MockObject |TestMessage $ message ;
1825
1926 public static function setUpBeforeClass (): void
2027 {
21- parent ::setUpBeforeClass ();
22-
23- // Initialize queue connection
24- static ::$ queueConnection = new QueueConnection ([
25- 'default ' => 'sync ' ,
26- 'connections ' => [
27- 'sync ' => [
28- 'driver ' => 'sync '
29- ]
30- ]
28+ TestingConfiguration::withConfigurations ([
29+ CacheConfiguration::class,
30+ QueueConfiguration::class,
31+ EnvConfiguration::class,
32+ LoggerConfiguration::class,
33+ MailConfiguration::class,
34+ ViewConfiguration::class,
3135 ]);
36+
37+ $ config = TestingConfiguration::getConfig ();
38+ $ config ->boot ();
39+
40+ static ::$ connection = new QueueConnection ($ config ["queue " ]);
41+ }
42+
43+ protected function setUp (): void
44+ {
45+ parent ::setUp ();
46+
47+ $ this ->context = $ this ->createMock (TestNotifiableModel::class);
48+ $ this ->message = $ this ->createMock (TestMessage::class);
3249 }
3350
3451 public function test_can_send_message_synchronously (): void
@@ -48,7 +65,7 @@ public function test_can_send_message_to_queue(): void
4865 $ this ->assertInstanceOf (MessagingQueueProducer::class, $ producer );
4966
5067 // Push to queue and verify
51- static ::$ queueConnection ->getAdapter ()->push ($ producer );
68+ static ::$ connection -> setConnection ( " beanstalkd " ) ->getAdapter ()->push ($ producer );
5269
5370 $ this ->context ->setMessageQueue ($ this ->message );
5471 }
@@ -62,7 +79,7 @@ public function test_can_send_message_to_specific_queue(): void
6279 $ this ->assertInstanceOf (MessagingQueueProducer::class, $ producer );
6380
6481 // Push to specific queue and verify
65- $ adapter = static ::$ queueConnection ->getAdapter ();
82+ $ adapter = static ::$ connection -> setConnection ( " beanstalkd " ) ->getAdapter ();
6683 $ adapter ->setQueue ($ queue );
6784 $ adapter ->push ($ producer );
6885
@@ -78,7 +95,7 @@ public function test_can_send_message_with_delay(): void
7895 $ this ->assertInstanceOf (MessagingQueueProducer::class, $ producer );
7996
8097 // Push to queue and verify
81- $ adapter = static ::$ queueConnection ->getAdapter ();
98+ $ adapter = static ::$ connection -> setConnection ( " beanstalkd " ) ->getAdapter ();
8299 $ adapter ->setSleep ($ delay );
83100 $ adapter ->push ($ producer );
84101
@@ -95,19 +112,11 @@ public function test_can_send_message_with_delay_on_specific_queue(): void
95112 $ this ->assertInstanceOf (MessagingQueueProducer::class, $ producer );
96113
97114 // Push to specific queue with delay and verify
98- $ adapter = static ::$ queueConnection ->getAdapter ();
115+ $ adapter = static ::$ connection -> setConnection ( " beanstalkd " ) ->getAdapter ();
99116 $ adapter ->setQueue ($ queue );
100117 $ adapter ->setSleep ($ delay );
101118 $ adapter ->push ($ producer );
102119
103120 $ this ->context ->sendMessageLaterOn ($ delay , $ queue , $ this ->message );
104121 }
105-
106- protected function setUp (): void
107- {
108- parent ::setUp ();
109-
110- $ this ->context = $ this ->createMock (TestNotifiableModel::class);
111- $ this ->message = $ this ->createMock (TestMessage::class);
112- }
113122}
0 commit comments