コード例 #1
0
 /**
  * Test string representation of ConnectionOptions with credentials.
  *
  * @return void
  */
 public function testStringRepresentationWithCredentials()
 {
     $options = new ConnectionOptions();
     $options->setUser("username");
     $options->setPass("password");
     $this->assertEquals("{\"lang\":\"php\",\"version\":\"0.8.0\",\"verbose\":false,\"pedantic\":false,\"user\":\"username\",\"pass\":\"password\"}", $options->__toString());
 }
コード例 #2
0
ファイル: ConnectionTest.php プロジェクト: aquilax/phpnats
 /**
  * setUp test suite
  *
  * @return void
  */
 public function setUp()
 {
     $options = new ConnectionOptions();
     if (!self::$isGnatsd) {
         time_nanosleep(1, 700000000);
         $options->setPort(4222);
     }
     $this->c = new Nats\Connection($options);
     $this->c->connect();
 }
コード例 #3
0
 /**
  * Tests Connection Options getters and setters. Only necessary for code coverage.
  *
  * @return void
  */
 public function testSettersAndGetters()
 {
     $options = new ConnectionOptions();
     $options->setHost('host')->setPort(4222)->setUser('user')->setPass('password')->setLang('lang')->setVersion('version')->setVerbose(true)->setPedantic(true)->setReconnect(true);
     $this->assertEquals('host', $options->getHost());
     $this->assertEquals(4222, $options->getPort());
     $this->assertEquals('user', $options->getUser());
     $this->assertEquals('password', $options->getPass());
     $this->assertEquals('lang', $options->getLang());
     $this->assertEquals('version', $options->getVersion());
     $this->assertTrue($options->isVerbose());
     $this->assertTrue($options->isPedantic());
     $this->assertTrue($options->isReconnect());
 }
コード例 #4
0
ファイル: Connection.php プロジェクト: repejota/phpnats
 /**
  * Connect to server.
  *
  * @param float $timeout Number of seconds until the connect() system call should timeout.
  *
  * @throws \Exception Exception raised if connection fails.
  * @return void
  */
 public function connect($timeout = null)
 {
     if ($timeout === null) {
         $timeout = intval(ini_get('default_socket_timeout'));
     }
     $this->timeout = $timeout;
     $this->streamSocket = $this->getStream($this->options->getAddress(), $timeout);
     $this->setStreamTimeout($timeout);
     $msg = 'CONNECT ' . $this->options;
     $this->send($msg);
     $connect_response = $this->receive();
     if (strpos($connect_response, '-ERR') !== false) {
         throw new \Exception("Failing connection: {$connect_response}");
     }
     $this->ping();
     $ping_response = $this->receive();
     if ($ping_response !== "PONG") {
         if (strpos($ping_response, '-ERR') !== false) {
             throw new \Exception("Failing on first ping: {$ping_response}");
         }
     }
 }