public function testConnectionFailLeadsToException() { $connection = new Connection('tcp://0.0.0.1:15'); try { $connection->connect(); $this->fail('Expected an exception!'); } catch (ConnectionException $ex) { $this->assertContains('Could not connect to a broker', $ex->getMessage()); $this->assertInstanceOf(ConnectionException::class, $ex->getPrevious(), 'There should be a previous exception.'); /** @var ConnectionException $prev */ $prev = $ex->getPrevious(); $hostInfo = $prev->getConnectionInfo(); $this->assertEquals('0.0.0.1', $hostInfo['host']); $this->assertEquals('15', $hostInfo['port']); } }
/** * @expectedException \Stomp\Exception\StompException */ public function testWriteFrameThrowsExceptionIfNotConnected() { $connection = new Connection('tcp://localhost'); $connection->writeFrame(new Frame()); }
/** * Check if client session has ben established * * @return boolean */ public function isConnected() { return !empty($this->sessionId) && $this->connection->isConnected(); }