33namespace PubSub \PubSubQueue \Tests \Unit ;
44
55use Carbon \Carbon ;
6- use ReflectionClass ;
7- use Google \Cloud \PubSub \Topic ;
8- use PHPUnit \Framework \TestCase ;
96use Google \Cloud \PubSub \Message ;
10- use Illuminate \Container \Container ;
117use Google \Cloud \PubSub \PubSubClient ;
128use Google \Cloud \PubSub \Subscription ;
13- use PubSub \ PubSubQueue \ PubSubQueue ;
14- use PubSub \ PubSubQueue \ Jobs \ PubSubJob ;
9+ use Google \ Cloud \ PubSub \ Topic ;
10+ use Illuminate \ Container \ Container ;
1511use Illuminate \Contracts \Queue \Queue as QueueContract ;
12+ use PHPUnit \Framework \TestCase ;
13+ use PubSub \PubSubQueue \Jobs \PubSubJob ;
14+ use PubSub \PubSubQueue \PubSubQueue ;
15+ use ReflectionClass ;
1616
1717class PubSubQueueTests extends TestCase
1818{
@@ -38,7 +38,7 @@ public function setUp()
3838 'sub1 ' => 'topic1 ' ,
3939 'sub2 ' => 'topic2 ' ,
4040 'sub3 ' => 'topic1 ' ,
41- ]
41+ ],
4242 ];
4343 $ this ->queue = $ this ->getMockBuilder (PubSubQueue::class)
4444 ->setConstructorArgs ([$ this ->client , 'default ' , $ this ->config ])
@@ -50,6 +50,7 @@ public function setUp()
5050 'subscription ' ,
5151 'availableAt ' ,
5252 'subscribeToTopic ' ,
53+ 'getQueue ' ,
5354 ])->getMock ();
5455 }
5556
@@ -113,7 +114,7 @@ public function testLater()
113114 $ this ->isType ('string ' ),
114115 $ this ->anything (),
115116 $ this ->callback (function ($ options ) use ($ delay_timestamp_string ) {
116- if (! isset ($ options ['available_at ' ]) || $ options ['available_at ' ] !== $ delay_timestamp_string ) {
117+ if (!isset ($ options ['available_at ' ]) || $ options ['available_at ' ] !== $ delay_timestamp_string ) {
117118 return false ;
118119 }
119120
@@ -224,15 +225,15 @@ public function testAcknowledgeAndPublish()
224225 ->willReturn ($ this ->result )
225226 ->with (
226227 $ this ->callback (function ($ message ) use ($ options , $ delay_timestamp_string ) {
227- if (! isset ($ message ['attributes ' ])) {
228+ if (!isset ($ message ['attributes ' ])) {
228229 return false ;
229230 }
230231
231- if (! isset ($ message ['attributes ' ]['available_at ' ]) || $ message ['attributes ' ]['available_at ' ] !== $ delay_timestamp_string ) {
232+ if (!isset ($ message ['attributes ' ]['available_at ' ]) || $ message ['attributes ' ]['available_at ' ] !== $ delay_timestamp_string ) {
232233 return false ;
233234 }
234235
235- if (! isset ($ message ['attributes ' ]['foo ' ]) || $ message ['attributes ' ]['foo ' ] != $ options ['foo ' ]) {
236+ if (!isset ($ message ['attributes ' ]['foo ' ]) || $ message ['attributes ' ]['foo ' ] != $ options ['foo ' ]) {
236237 return false ;
237238 }
238239
@@ -259,6 +260,32 @@ public function testGetTopic()
259260 $ this ->assertTrue ($ queue ->getTopic ('test ' ) instanceof Topic);
260261 }
261262
263+ public function testGetTopicUsingSubscriber ()
264+ {
265+ $ this ->client ->method ('topic ' )
266+ ->willReturn ($ this ->topic );
267+
268+ $ this ->queue ->method ('getQueue ' )
269+ ->willReturn ($ this ->topic );
270+
271+ $ queue = $ this ->getMockBuilder (PubSubQueue::class)
272+ ->setConstructorArgs ([$ this ->client , 'default ' , $ this ->config ])
273+ ->setMethods ()
274+ ->getMock ();
275+ $ this ->assertTrue ($ queue ->getTopicUsingSubscriber ('sub1 ' ) instanceof Topic);
276+
277+ }
278+
279+ public function testGetQueue ()
280+ {
281+ $ queue = $ this ->getMockBuilder (PubSubQueue::class)
282+ ->setConstructorArgs ([$ this ->client , 'default ' , $ this ->config ])
283+ ->setMethods ()
284+ ->getMock ();
285+
286+ $ this ->assertTrue ($ queue ->getQueue ('sub1 ' ) === 'topic1 ' );
287+
288+ }
262289 public function testSubscribtionIsCreated ()
263290 {
264291 $ this ->topic ->method ('subscription ' )
@@ -298,4 +325,5 @@ public function testGetPubSub()
298325 {
299326 $ this ->assertTrue ($ this ->queue ->getPubSub () instanceof PubSubClient);
300327 }
328+
301329}
0 commit comments