コード例 #1
0
ファイル: CronjobTest.php プロジェクト: thefox/phpchat
 public function testCreateGuzzleHttpClient()
 {
     $runName = uniqid('', true);
     $prvFileName = 'testfile_cronjob_id_rsa_' . date('Ymd_His') . '_' . $runName . '.prv';
     $pubFileName = 'testfile_cronjob_id_rsa_' . date('Ymd_His') . '_' . $runName . '.pub';
     $settignsFileName = 'testfile_cronjob_settings_' . date('Ymd_His') . '_' . $runName . '.pub';
     file_put_contents('test_data/' . $prvFileName, static::NODE_LOCAL_SSL_KEY_PRV);
     file_put_contents('test_data/' . $pubFileName, static::NODE_LOCAL_SSL_KEY_PUB);
     $settings = new Settings('test_data/' . $settignsFileName);
     $settings->data['datadir'] = 'test_data';
     $settings->data['node']['id'] = Node::genIdHexStr(static::NODE_LOCAL_SSL_KEY_PUB);
     $settings->data['node']['sslKeyPrvPass'] = '******';
     $settings->data['node']['sslKeyPrvPath'] = 'test_data/' . $prvFileName;
     $settings->data['node']['sslKeyPubPath'] = 'test_data/' . $pubFileName;
     $settings->data['node']['bridge']['client']['enabled'] = true;
     $localNode = new Node();
     $localNode->setIdHexStr($settings->data['node']['id']);
     $localNode->setUri($settings->data['node']['uriLocal']);
     $localNode->setSslKeyPub(file_get_contents($settings->data['node']['sslKeyPubPath']));
     $table = new Table();
     $table->setDatadirBasePath($settings->data['datadir']);
     $table->setLocalNode($localNode);
     $nodesNewDb = new NodesNewDb('test_data/testfile_cronjob_nodesnewdb2.yml');
     $nodesNewDb->nodeAddConnect('tcp://192.168.241.21', false);
     $nodesNewDb->nodeAddConnect('tcp://192.168.241.22', true);
     $nodesNewDb->nodeAddFind('cafed00d-2131-4159-8e11-0b4dbadb1742', false);
     $nodesNewDb->nodeAddFind('cafed00d-2131-4159-8e11-0b4dbadb1743', true);
     $cronjobLog = new Logger('cronjob');
     #$cronjobLog->pushHandler(new LoggerStreamHandler('php://stdout', Logger::DEBUG));
     $cronjob = new Cronjob();
     $cronjob->setLog($cronjobLog);
     $cronjob->setSettings($settings);
     $cronjob->setTable($table);
     $cronjob->setNodesNewDb($nodesNewDb);
     $httpClient = $cronjob->createGuzzleHttpClient();
     #fwrite(STDOUT, 'client: '.get_class($httpClient).''.PHP_EOL);
     #\Doctrine\Common\Util\Debug::dump($httpClient);
     $this->assertTrue(is_object($httpClient));
     $url = 'http://www.example.com/';
     $response = null;
     try {
         #fwrite(STDOUT, 'get url: '.$url.''.PHP_EOL);
         $request = $httpClient->get($url);
         #fwrite(STDOUT, 'request: '.get_class($request).''.PHP_EOL);
         $response = $request->send();
         #fwrite(STDOUT, 'response: '.get_class($response).''.PHP_EOL);
     } catch (Exception $e) {
         #fwrite(STDOUT, 'url failed, "'.$url.'": '.$e->getMessage().PHP_EOL);
     }
     /*if($response){
     			fwrite(STDOUT, 'response: '.$response->getStatusCode().PHP_EOL);
     			fwrite(STDOUT, 'content-type: '.$response->getHeader('content-type').PHP_EOL);
     		}
     		else{
     			fwrite(STDOUT, 'response failed'.PHP_EOL);
     		}*/
 }
コード例 #2
0
ファイル: NodesNewDbTest.php プロジェクト: thefox/phpchat
 public function testGetNodes()
 {
     $db = new NodesNewDb();
     $this->assertEquals(array(), $db->getNodes());
     $this->assertEquals(0, count($db->getNodes()));
     $db->nodeAddFind('cafed00d-2131-4159-8e11-0b4dbadb1738');
     $this->assertEquals(1, count($db->getNodes()));
 }