|
| 1 | +<?php |
| 2 | + |
| 3 | + |
| 4 | +namespace Enqueue\Stomp\Tests\Functional; |
| 5 | + |
| 6 | + |
| 7 | +use Enqueue\Stomp\StompConnectionFactory; |
| 8 | +use Enqueue\Test\RabbitmqStompExtension; |
| 9 | +use Stomp\Network\Observer\HeartbeatEmitter; |
| 10 | +use Stomp\Network\Observer\ServerAliveObserver; |
| 11 | + |
| 12 | +class StompConnectionFactoryTest extends \PHPUnit\Framework\TestCase |
| 13 | +{ |
| 14 | + use RabbitmqStompExtension; |
| 15 | + |
| 16 | + public function testShouldNotCreateConnectionWithSendHeartbeat() |
| 17 | + { |
| 18 | + $dsn = $this->getDsn() . '&send_heartbeat=2000'; |
| 19 | + $factory = new StompConnectionFactory($dsn); |
| 20 | + $this->expectException(HeartbeatException::class); |
| 21 | + $factory->createContext()->getStomp(); |
| 22 | + } |
| 23 | + |
| 24 | + public function testShouldCreateConnectionWithSendHeartbeat() |
| 25 | + { |
| 26 | + $dsn = $this->getDsn() . '&send_heartbeat=2000&read_timeout=1'; |
| 27 | + $factory = new StompConnectionFactory($dsn); |
| 28 | + $context = $factory->createContext(); |
| 29 | + |
| 30 | + $observers = $context->getStomp()->getConnection()->getObservers()->getObservers(); |
| 31 | + $this->assertAttributeEquals([2000, 0], 'heartbeat', $context->getStomp()); |
| 32 | + $this->assertCount(1, $observers); |
| 33 | + $this->assertInstanceOf(HeartbeatEmitter::class, $observers[0]); |
| 34 | + } |
| 35 | + |
| 36 | + public function testShouldCreateConnectionWithReceiveHeartbeat() |
| 37 | + { |
| 38 | + $dsn = $this->getDsn() . '&receive_heartbeat=2000'; |
| 39 | + $factory = new StompConnectionFactory($dsn); |
| 40 | + $context = $factory->createContext(); |
| 41 | + |
| 42 | + $observers = $context->getStomp()->getConnection()->getObservers()->getObservers(); |
| 43 | + $this->assertAttributeEquals([0, 2000], 'heartbeat', $context->getStomp()); |
| 44 | + $this->assertCount(1, $observers); |
| 45 | + $this->assertInstanceOf(ServerAliveObserver::class, $observers[0]); |
| 46 | + } |
| 47 | + |
| 48 | +} |
0 commit comments