This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
1 | <?php |
||
2 | namespace NeedleProject\LaravelRabbitMq; |
||
3 | |||
4 | use PhpAmqpLib\Channel\AMQPChannel; |
||
5 | use PhpAmqpLib\Connection\AbstractConnection; |
||
6 | use PhpAmqpLib\Connection\AMQPStreamConnection; |
||
7 | use Tests\NeedleProject\LaravelRabbitMq\Stubs\ConnectionDetailsStub; |
||
8 | use PHPUnit\Framework\TestCase; |
||
9 | |||
10 | class AMQPConnectionTest extends TestCase |
||
11 | { |
||
12 | public function testCreateWithEmptyDetails() |
||
13 | { |
||
14 | $connection = ConnectionDetailsStub::createConnection('foo', []); |
||
15 | $details = $connection->getConnectionDetails(); |
||
16 | |||
17 | $this->assertEquals('127.0.0.1', $details['hostname']); |
||
18 | $this->assertEquals(5672, $details['port']); |
||
19 | $this->assertEquals('guest', $details['username']); |
||
20 | $this->assertEquals('guest', $details['password']); |
||
21 | $this->assertEquals('/', $details['vhost']); |
||
22 | $this->assertEquals(true, $details['lazy']); |
||
23 | $this->assertEquals(3, $details['read_write_timeout']); |
||
24 | $this->assertEquals(3, $details['connect_timeout']); |
||
25 | $this->assertEquals(0, $details['heartbeat']); |
||
26 | } |
||
27 | |||
28 | public function testCreateWithAllDetails() |
||
29 | { |
||
30 | $connection = ConnectionDetailsStub::createConnection( |
||
31 | 'foo', |
||
32 | [ |
||
33 | 'hostname' => 'foo', |
||
34 | 'port' => 1, |
||
35 | 'username' => 'bar', |
||
36 | 'password' => 'baz', |
||
37 | 'vhost' => 'ahost', |
||
38 | 'lazy' => false, |
||
39 | 'read_write_timeout' => 99, |
||
40 | 'connect_timeout' => 98, |
||
41 | 'heartbeat' => 97, |
||
42 | ] |
||
43 | ); |
||
44 | |||
45 | $details = $connection->getConnectionDetails(); |
||
46 | |||
47 | $this->assertEquals('foo', $details['hostname']); |
||
48 | $this->assertEquals(1, $details['port']); |
||
49 | $this->assertEquals('bar', $details['username']); |
||
50 | $this->assertEquals('baz', $details['password']); |
||
51 | $this->assertEquals('ahost', $details['vhost']); |
||
52 | $this->assertEquals(false, $details['lazy']); |
||
53 | $this->assertEquals(99, $details['read_write_timeout']); |
||
54 | $this->assertEquals(98, $details['connect_timeout']); |
||
55 | $this->assertEquals(97, $details['heartbeat']); |
||
56 | } |
||
57 | |||
58 | public function testCreateWithInvalidArgumentsDetails() |
||
59 | { |
||
60 | $this->expectException(\InvalidArgumentException::class); |
||
61 | $this->expectExceptionMessage("Cannot create connection foo, received unknown arguments: foo, bar!"); |
||
62 | ConnectionDetailsStub::createConnection( |
||
63 | 'foo', |
||
64 | [ |
||
65 | 'foo' => 'bar', |
||
66 | 'bar' => 'baz' |
||
67 | ] |
||
68 | ); |
||
69 | } |
||
70 | |||
71 | public function testConnectionGetChannel() |
||
72 | { |
||
73 | $channelMock = $this->createMock(AMQPChannel::class); |
||
74 | $connectionMock = $this->createMock(AbstractConnection::class); |
||
75 | |||
76 | $connectionMock->expects($this->once()) |
||
77 | ->method('channel') |
||
78 | ->willReturn($channelMock); |
||
79 | |||
80 | $amqpConnection = new class('foo', [], $connectionMock) extends AMQPConnection { |
||
81 | /** |
||
82 | * @var AMQPStreamConnection |
||
83 | */ |
||
84 | private $mock; |
||
85 | |||
86 | /** |
||
87 | * constructor. |
||
88 | * |
||
89 | * @param string $aliasName |
||
90 | * @param array $connectionDetails |
||
91 | * @param AMQPStreamConnection $mock |
||
92 | */ |
||
93 | public function __construct($aliasName, array $connectionDetails = [], $mock = null) |
||
94 | { |
||
95 | $this->mock = $mock; |
||
96 | parent::__construct($aliasName, $connectionDetails); |
||
97 | } |
||
98 | |||
99 | /** |
||
100 | * @return AbstractConnection |
||
101 | */ |
||
102 | protected function getConnection(): AbstractConnection |
||
103 | { |
||
104 | return $this->mock; |
||
105 | } |
||
106 | }; |
||
107 | |||
108 | $this->assertEquals($channelMock, $amqpConnection->getChannel()); |
||
109 | } |
||
110 | |||
111 | public function testAliasName() |
||
112 | { |
||
113 | $amqpConnection = new AMQPConnection('foo', []); |
||
114 | $this->assertEquals($amqpConnection->getAliasName(), 'foo'); |
||
115 | } |
||
116 | |||
117 | public function testLazyConnection() |
||
118 | { |
||
119 | $tester = $this; |
||
120 | $abstractConnectionMock = $this->createMock(AbstractConnection::class); |
||
121 | |||
122 | new class('foo', ['lazy' => false], $tester, $abstractConnectionMock) extends AMQPConnection { |
||
123 | private $tester; |
||
124 | |||
125 | private $abstractConnectionMock; |
||
126 | |||
127 | /** |
||
128 | * constructor. |
||
129 | * |
||
130 | * @param string $aliasName |
||
131 | * @param array $connectionDetails |
||
132 | * @param null $tester |
||
0 ignored issues
–
show
Documentation
Bug
introduced
by
![]() |
|||
133 | */ |
||
134 | public function __construct($aliasName, array $connectionDetails = [], $tester = null, $abstractConnectionMock = null) |
||
135 | { |
||
136 | $this->tester = $tester; |
||
137 | $this->abstractConnectionMock = $abstractConnectionMock; |
||
138 | parent::__construct($aliasName, $connectionDetails); |
||
139 | } |
||
140 | |||
141 | /** |
||
142 | * @return AbstractConnection |
||
143 | */ |
||
144 | protected function getConnection(): AbstractConnection |
||
145 | { |
||
146 | $this->tester->assertTrue(true); |
||
147 | return $this->abstractConnectionMock; |
||
148 | } |
||
149 | }; |
||
150 | } |
||
151 | |||
152 | public function testReconnect() |
||
153 | { |
||
154 | $channelMock = $this->createMock(AMQPChannel::class); |
||
155 | $channelMock->expects($this->once()) |
||
156 | ->method('close') |
||
157 | ->willReturn(null); |
||
158 | |||
159 | $connectionMock = $this->createMock(AbstractConnection::class); |
||
160 | |||
161 | $connectionMock->expects($this->once()) |
||
162 | ->method('channel') |
||
163 | ->willReturn($channelMock); |
||
164 | $connectionMock->expects($this->once()) |
||
165 | ->method('reconnect') |
||
166 | ->willReturn(null); |
||
167 | |||
168 | $amqpConnection = new class('foo', [], $connectionMock) extends AMQPConnection { |
||
169 | /** |
||
170 | * @var AbstractConnection |
||
171 | */ |
||
172 | private $mock; |
||
173 | |||
174 | /** |
||
175 | * constructor. |
||
176 | * |
||
177 | * @param string $aliasName |
||
178 | * @param array $connectionDetails |
||
179 | * @param AbstractConnection $mock |
||
180 | */ |
||
181 | public function __construct($aliasName, array $connectionDetails = [], $mock = null) |
||
182 | { |
||
183 | $this->mock = $mock; |
||
184 | parent::__construct($aliasName, $connectionDetails); |
||
185 | } |
||
186 | |||
187 | /** |
||
188 | * @return AbstractConnection |
||
189 | */ |
||
190 | protected function getConnection(): AbstractConnection |
||
191 | { |
||
192 | return $this->mock; |
||
193 | } |
||
194 | }; |
||
195 | |||
196 | $amqpConnection->reconnect(); |
||
197 | } |
||
198 | } |
||
199 |