-
Notifications
You must be signed in to change notification settings - Fork 436
Expand file tree
/
Copy pathGpsContextTest.php
More file actions
103 lines (81 loc) · 2.89 KB
/
GpsContextTest.php
File metadata and controls
103 lines (81 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
namespace Enqueue\Gps\Tests;
use Enqueue\Gps\GpsContext;
use Enqueue\Gps\GpsQueue;
use Enqueue\Gps\GpsTopic;
use Google\Cloud\Core\Exception\ConflictException;
use Google\Cloud\PubSub\PubSubClient;
use Interop\Queue\Exception\InvalidDestinationException;
use PHPUnit\Framework\TestCase;
class GpsContextTest extends TestCase
{
public function testShouldDeclareTopic()
{
$client = $this->createPubSubClientMock();
$client
->expects($this->once())
->method('createTopic')
->with('topic-name')
;
$topic = new GpsTopic('topic-name');
$context = new GpsContext($client);
$context->declareTopic($topic);
}
public function testDeclareTopicShouldCatchConflictException()
{
$client = $this->createPubSubClientMock();
$client
->expects($this->once())
->method('createTopic')
->willThrowException(new ConflictException(''))
;
$topic = new GpsTopic('');
$context = new GpsContext($client);
$context->declareTopic($topic);
}
public function testShouldSubscribeTopicToQueue()
{
$client = $this->createPubSubClientMock();
$client
->expects($this->once())
->method('subscribe')
->with('queue-name', 'topic-name', $this->identicalTo(['ackDeadlineSeconds' => 10]))
;
$topic = new GpsTopic('topic-name');
$queue = new GpsQueue('queue-name');
$context = new GpsContext($client);
$context->subscribe($topic, $queue);
}
public function testSubscribeShouldCatchConflictException()
{
$client = $this->createPubSubClientMock();
$client
->expects($this->once())
->method('subscribe')
->willThrowException(new ConflictException(''))
;
$topic = new GpsTopic('topic-name');
$queue = new GpsQueue('queue-name');
$context = new GpsContext($client);
$context->subscribe($topic, $queue);
}
public function testCreateConsumerShouldThrowExceptionIfInvalidDestination()
{
$context = new GpsContext($this->createPubSubClientMock());
$this->expectException(InvalidDestinationException::class);
$this->expectExceptionMessage('The destination must be an instance of Enqueue\Gps\GpsQueue but got Enqueue\Gps\GpsTopic');
$context->createConsumer(new GpsTopic(''));
}
public function testShouldReturnOptions()
{
$context = new GpsContext($this->createPubSubClientMock(), ['foo' => 'fooVal']);
$this->assertSame(['ackDeadlineSeconds' => 10, 'foo' => 'fooVal'], $context->getOptions());
}
/**
* @return PubSubClient|\PHPUnit\Framework\MockObject\MockObject|PubSubClient
*/
private function createPubSubClientMock()
{
return $this->createMock(PubSubClient::class);
}
}