ChannelTest::testCommitTransaction()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace AMQPAL\Adapter\AMQP;
4
5
use Prophecy\Argument;
6
use AMQPAL\Options\ExchangeOptions;
7
use AMQPAL\Options\QueueOptions;
8
9
class ChannelTest extends \PHPUnit_Framework_TestCase
10
{
11
12
    public function testSetResource()
13
    {
14
        $resource = $this->prophesize(\AMQPChannel::class);
15
16
        $channel = new Channel();
17
        $channel->setResource($resource->reveal());
18
19
        static::assertSame($resource->reveal(), $channel->getResource());
20
    }
21
22
    public function testIsConnected()
23
    {
24
        $resource = $this->prophesize(\AMQPChannel::class);
25
26
        $resource->isConnected()->shouldBeCalled()->willReturn(true);
27
28
        $channel = new Channel();
29
        $channel->setResource($resource->reveal());
30
31
        static::assertTrue($channel->isConnected());
32
    }
33
34
    public function testGetChannelId()
35
    {
36
        $resource = $this->prophesize(\AMQPChannel::class);
37
38
        $resource->getChannelId()->shouldBeCalled()->willReturn(1234);
39
40
        $channel = new Channel();
41
        $channel->setResource($resource->reveal());
42
43
        static::assertEquals(1234, $channel->getChannelId());
44
    }
45
46
    public function testSetQos()
47
    {
48
        $resource = $this->prophesize(\AMQPChannel::class);
49
50
        $resource->qos(2, 3)->shouldBeCalled();
51
52
        $channel = new Channel();
53
        $channel->setResource($resource->reveal());
54
55
        $channel->setQos(2, 3);
56
    }
57
58
    public function testStartTransaction()
59
    {
60
        $resource = $this->prophesize(\AMQPChannel::class);
61
62
        $resource->startTransaction()->shouldBeCalled();
63
64
        $channel = new Channel();
65
        $channel->setResource($resource->reveal());
66
67
        $channel->startTransaction();
68
    }
69
70
    public function testCommitTransaction()
71
    {
72
        $resource = $this->prophesize(\AMQPChannel::class);
73
74
        $resource->commitTransaction()->shouldBeCalled();
75
76
        $channel = new Channel();
77
        $channel->setResource($resource->reveal());
78
79
        $channel->commitTransaction();
80
    }
81
82
    public function testRollbackTransaction()
83
    {
84
        $resource = $this->prophesize(\AMQPChannel::class);
85
86
        $resource->rollbackTransaction()->shouldBeCalled();
87
88
        $channel = new Channel();
89
        $channel->setResource($resource->reveal());
90
91
        $channel->rollbackTransaction();
92
    }
93
94
    public function testBasicRecoverWithDefaults()
95
    {
96
        $resource = $this->prophesize(\AMQPChannel::class);
97
98
        $resource->basicRecover(true)->shouldBeCalled();
99
100
        $channel = new Channel();
101
        $channel->setResource($resource->reveal());
102
103
        $channel->basicRecover();
104
    }
105
106
    public function testBasicRecoverWithNoRequeue()
107
    {
108
        $resource = $this->prophesize(\AMQPChannel::class);
109
110
        $resource->basicRecover(false)->shouldBeCalled();
111
112
        $channel = new Channel();
113
        $channel->setResource($resource->reveal());
114
115
        $channel->basicRecover(false);
116
    }
117
118
    public function testGetConnection()
119
    {
120
        $connection = $this->prophesize(Connection::class);
121
        $adapter = $this->prophesize(AMQP::class);
122
123
        $adapter->getConnection()->willReturn($connection->reveal());
124
125
        $channel = new Channel();
126
        $channel->setConnection($connection->reveal());
127
128
        static::assertSame($connection->reveal(), $channel->getConnection());
129
    }
130
131
    public function testCreateExchangeWithResource()
132
    {
133
        $exchangeOptions = $this->prophesize(ExchangeOptions::class);
134
        $exchangePrototype = $this->prophesize(Exchange::class);
135
        $resource = $this->prophesize(\AMQPExchange::class);
136
137
        $exchangePrototype->setResource($resource->reveal())->shouldBeCalled();
138
        $exchangePrototype->setChannel(Argument::type(Channel::class))->shouldBeCalled();
139
        $exchangePrototype->setOptions($exchangeOptions->reveal())->shouldBeCalled();
140
141
        $channel = new Channel($exchangePrototype->reveal());
142
143
        $exchange = $channel->createExchange($exchangeOptions->reveal(), $resource->reveal());
144
145
        static::assertInstanceOf(Exchange::class, $exchange);
146
    }
147
148
    public function testCreateExchange()
149
    {
150
        $exchangeOptions = $this->prophesize(ExchangeOptions::class);
151
        $exchangePrototype = $this->prophesize(Exchange::class);
152
        $resource = $this->prophesize(\AMQPExchange::class);
153
154
        $exchangePrototype->setResource($resource->reveal())->shouldBeCalled();
155
        $exchangePrototype->setChannel(Argument::type(Channel::class))->shouldBeCalled();
156
        $exchangePrototype->setOptions($exchangeOptions->reveal())->shouldBeCalled();
157
158
        $channel = static::getMockBuilder(Channel::class)
159
            ->setMethods(['createExchangeResource'])
160
            ->setConstructorArgs([$exchangePrototype->reveal()])
161
            ->getMock();
162
163
        $channel->expects(static::once())
164
            ->method('createExchangeResource')
165
            ->willReturn($resource->reveal());
166
167
        $exchange = $channel->createExchange($exchangeOptions->reveal());
168
169
        static::assertInstanceOf(Exchange::class, $exchange);
170
    }
171
172
    public function testCreateQueueWithResource()
173
    {
174
        $queueOptions = $this->prophesize(QueueOptions::class);
175
        $queuePrototype = $this->prophesize(Queue::class);
176
        $resource = $this->prophesize(\AMQPQueue::class);
177
178
        $queuePrototype->setResource($resource->reveal())->shouldBeCalled();
179
        $queuePrototype->setChannel(Argument::type(Channel::class))->shouldBeCalled();
180
        $queuePrototype->setOptions($queueOptions->reveal())->shouldBeCalled();
181
182
        $channel = new Channel(null, $queuePrototype->reveal());
183
184
        $exchange = $channel->createQueue($queueOptions->reveal(), $resource->reveal());
185
186
        static::assertInstanceOf(Queue::class, $exchange);
187
    }
188
189
    public function testCreateQueue()
190
    {
191
        $queueOptions = $this->prophesize(QueueOptions::class);
192
        $queuePrototype = $this->prophesize(Queue::class);
193
        $resource = $this->prophesize(\AMQPQueue::class);
194
195
        $queuePrototype->setResource($resource->reveal())->shouldBeCalled();
196
        $queuePrototype->setChannel(Argument::type(Channel::class))->shouldBeCalled();
197
        $queuePrototype->setOptions($queueOptions->reveal())->shouldBeCalled();
198
199
        $channel = static::getMockBuilder(Channel::class)
200
            ->setMethods(['createQueueResource'])
201
            ->setConstructorArgs([null, $queuePrototype->reveal()])
202
            ->getMock();
203
204
        $channel->expects(static::once())
205
            ->method('createQueueResource')
206
            ->willReturn($resource->reveal());
207
208
        $exchange = $channel->createQueue($queueOptions->reveal());
209
210
        static::assertInstanceOf(Queue::class, $exchange);
211
    }
212
}
213