|
3 | 3 | namespace VladimirYuldashev\LaravelQueueRabbitMQ\Tests\Functional; |
4 | 4 |
|
5 | 5 | use Exception; |
| 6 | +use PhpAmqpLib\Channel\AMQPChannel; |
6 | 7 | use ReflectionClass; |
7 | 8 | use ReflectionException; |
8 | 9 | use VladimirYuldashev\LaravelQueueRabbitMQ\Tests\TestCase as BaseTestCase; |
@@ -234,4 +235,34 @@ protected function callProperty($object, string $property): mixed |
234 | 235 |
|
235 | 236 | return $property->getValue($object); |
236 | 237 | } |
| 238 | + |
| 239 | + public function testConnectChannel(): void |
| 240 | + { |
| 241 | + $queue = $this->connection(); |
| 242 | + $this->assertFalse($queue->getConnection()->isConnected()); |
| 243 | + |
| 244 | + /** @var AMQPChannel $channel */ |
| 245 | + $channel = $this->callMethod($queue, 'getChannel'); |
| 246 | + $this->assertTrue($queue->getConnection()->isConnected()); |
| 247 | + $this->assertSame($channel, $this->callProperty($queue, 'channel')); |
| 248 | + $this->assertTrue($channel->is_open()); |
| 249 | + } |
| 250 | + |
| 251 | + public function testReconnect(): void |
| 252 | + { |
| 253 | + $queue = $this->connection(); |
| 254 | + $this->assertFalse($queue->getConnection()->isConnected()); |
| 255 | + |
| 256 | + // connect |
| 257 | + $channel = $this->callMethod($queue, 'getChannel'); |
| 258 | + $this->assertTrue($queue->getConnection()->isConnected()); |
| 259 | + $this->assertSame($channel, $this->callProperty($queue, 'channel')); |
| 260 | + |
| 261 | + // reconnect |
| 262 | + $queue->getConnection()->close(); |
| 263 | + $this->assertFalse($queue->getConnection()->isConnected()); |
| 264 | + $this->callMethod($queue, 'reconnect'); |
| 265 | + $this->assertTrue($queue->getConnection()->isConnected()); |
| 266 | + $this->assertTrue($queue->getChannel()->is_open()); |
| 267 | + } |
237 | 268 | } |
0 commit comments