示例#1
0
 public function testOthers()
 {
     $this->assertNull($this->object->project);
     $this->object->setProject('demo');
     $this->assertEquals('demo', $this->object->getProject());
     $this->object->setTimeout(0);
     $this->assertFalse($this->object->hasRespond());
     $this->object->sendCommand(CMD_OK);
     $this->assertFalse($this->object->hasRespond());
     $this->object->sendCommand(CMD_SEARCH_GET_DB);
     usleep(50000);
     $this->assertTrue($this->object->hasRespond());
     $res = $this->object->respond;
     $this->assertEquals(CMD_OK_DB_INFO, $res->arg);
     $this->assertEquals('Database()', $res->buf);
     // read timeout
     try {
         stream_set_timeout($this->object->socket, 2);
         $this->object->getRespond();
     } catch (XSException $e) {
     }
     $this->assertInstanceOf('XSException', $e);
     $this->assertRegExp('/timeout/', $e->getMessage());
     // send cmd
     $this->object->reopen();
     $this->object->project = 'demo';
     $cmd = new XSCommand(array('cmd' => CMD_QUERY_GET_STRING, 'buf' => 'hello'));
     $res = $this->object->execCommand($cmd);
     $this->assertEquals(CMD_OK_QUERY_STRING, $res->arg);
     $this->assertEquals('Xapian::Query(Zhello:(pos=1))', $res->buf);
     // test unimp cmd
     try {
         $e = null;
         $this->object->execCommand(array('cmd' => CMD_INDEX_SUBMIT));
     } catch (XSException $e) {
     }
     $this->assertInstanceOf('XSException', $e);
     $this->assertEquals('Command not implemented', $e->getMessage());
     // test io closed
     try {
         $e = null;
         $err = error_reporting(0);
         fclose($this->object->socket);
         $this->object->sendCommand(CMD_INDEX_SUBMIT);
     } catch (XSException $e) {
     }
     $this->assertInstanceOf('XSException', $e);
     $this->assertRegExp('/unknown/', $e->getMessage());
     error_reporting($err);
 }