-
-
Notifications
You must be signed in to change notification settings - Fork 58
/
SimpleStompTest.php
128 lines (118 loc) · 3.8 KB
/
SimpleStompTest.php
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
/*
* This file is part of the Stomp package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Stomp\Tests\Unit;
use PHPUnit\Framework\TestCase;
use Stomp\Client;
use Stomp\SimpleStomp;
use Stomp\Protocol\Protocol;
use Stomp\Protocol\Version;
use Stomp\Transport\Frame;
use Stomp\Transport\Message;
/**
* SimpleStompTest
*
* @package Stomp\Tests\Unit
* @author Jens Radtke <swefl.oss@fin-sn.de>
*/
class SimpleStompTest extends TestCase
{
public function testSendIsMappedToClient()
{
$queue = 'queue';
$message = new Message('content');
$stomp = $this->getMockBuilder(Client::class)
->disableOriginalConstructor()
->onlyMethods(['send'])
->getMock();
$stomp->expects($this->once())->method('send')->with($queue, $message);
/**
* @var $stomp Client
*/
$simpleStomp = new SimpleStomp($stomp);
$simpleStomp->send($queue, $message);
}
/**
* @param $method
* @param array $parameters
* @param array $expectedSendFrameParameters
* @param $result
*
* @dataProvider actionToProtocolProvider
*/
public function testActionToProtocolMapping($method, array $parameters, array $expectedSendFrameParameters, $result)
{
$stomp = $this->getMockBuilder(Client::class)
->disableOriginalConstructor()
->onlyMethods(['sendFrame', 'getProtocol'])
->getMock();
$stomp->expects($this->any())
->method('getProtocol')
->willReturn(new Protocol('test', Version::VERSION_1_2));
$stomp->expects($this->once())
->method('sendFrame')
->with($expectedSendFrameParameters[0], $expectedSendFrameParameters[1])
->willReturn($result);
/**
* @var $stomp Client
*/
$client = new SimpleStomp($stomp);
$this->assertEquals($result, call_user_func_array([$client, $method], $parameters));
}
public function actionToProtocolProvider()
{
$protocol = new Protocol('test', Version::VERSION_1_2);
return [
'subscribe' => [
'subscribe',
['/test/queue', 55, 'auto', 'S=5',['myHeader' => 'myHeaderValue']],
[
$protocol->getSubscribeFrame('/test/queue', 55, 'auto', 'S=5')
->addHeaders(['myHeader' => 'myHeaderValue']),
null
],
true
],
'unsubscribe' => [
'unsubscribe',
['/test/queue', 44, ['myHeader' => 'myHeaderValue']],
[$protocol->getUnsubscribeFrame('/test/queue', 44)->addHeaders(['myHeader' => 'myHeaderValue']), null],
true
],
'begin' => [
'begin',
[11211],
[$protocol->getBeginFrame(11211), false],
true
],
'commit' => [
'commit',
[2211],
[$protocol->getCommitFrame(2211), false],
true
],
'abort' => [
'abort',
[1122],
[$protocol->getAbortFrame(1122), false],
true
],
'ack' => [
'ack',
[new Frame('MESSAGE', ['id' => 121])],
[$protocol->getAckFrame(new Frame('MESSAGE', ['id' => 121])), false],
null
],
'nack' => [
'nack',
[new Frame('MESSAGE', ['ack' => 212])],
[$protocol->getNackFrame(new Frame('MESSAGE', ['ack' => 212])), false],
null
]
];
}
}