mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-11 04:17:48 +00:00
Merge remote-tracking branch 'origin/master' into 0.7.4
This commit is contained in:
commit
46e6cd37b7
@ -5,10 +5,9 @@ php:
|
|||||||
|
|
||||||
before_script:
|
before_script:
|
||||||
- pecl install channel://pecl.php.net/pthreads-0.0.44
|
- pecl install channel://pecl.php.net/pthreads-0.0.44
|
||||||
- git clone --depth=100 --quiet --branch=tests git://github.com/PocketMine/PocketMine-MP.git $(pwd)/tests/
|
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- phpunit tests/
|
- phpunit src/tests/
|
||||||
|
|
||||||
notifications:
|
notifications:
|
||||||
email: false
|
email: false
|
||||||
|
@ -31,7 +31,9 @@ class ConsoleAPI{
|
|||||||
|
|
||||||
public function init(){
|
public function init(){
|
||||||
$this->server->schedule(2, array($this, "handle"), array(), true);
|
$this->server->schedule(2, array($this, "handle"), array(), true);
|
||||||
$this->loop = new ConsoleLoop();
|
if(!defined("NO_THREADS")){
|
||||||
|
$this->loop = new ConsoleLoop();
|
||||||
|
}
|
||||||
$this->register("help", "[page|command name]", array($this, "defaultCommands"));
|
$this->register("help", "[page|command name]", array($this, "defaultCommands"));
|
||||||
$this->register("status", "", array($this, "defaultCommands"));
|
$this->register("status", "", array($this, "defaultCommands"));
|
||||||
$this->register("difficulty", "<0|1|2|3>", array($this, "defaultCommands"));
|
$this->register("difficulty", "<0|1|2|3>", array($this, "defaultCommands"));
|
||||||
@ -42,9 +44,11 @@ class ConsoleAPI{
|
|||||||
|
|
||||||
function __destruct(){
|
function __destruct(){
|
||||||
$this->server->deleteEvent($this->event);
|
$this->server->deleteEvent($this->event);
|
||||||
$this->loop->stop();
|
if(!defined("NO_THREADS")){
|
||||||
$this->loop->notify();
|
$this->loop->stop();
|
||||||
//$this->loop->join();
|
$this->loop->notify();
|
||||||
|
//$this->loop->join();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function defaultCommands($cmd, $params, $issuer, $alias){
|
public function defaultCommands($cmd, $params, $issuer, $alias){
|
||||||
@ -248,6 +252,9 @@ class ConsoleAPI{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function handle($time){
|
public function handle($time){
|
||||||
|
if(defined("NO_THREADS")){
|
||||||
|
return;
|
||||||
|
}
|
||||||
if($this->loop->line !== false){
|
if($this->loop->line !== false){
|
||||||
$line = trim($this->loop->line);
|
$line = trim($this->loop->line);
|
||||||
$this->loop->line = false;
|
$this->loop->line = false;
|
||||||
|
@ -281,7 +281,7 @@ class ServerAPI{
|
|||||||
if($this->getProperty("auto-save") === true){
|
if($this->getProperty("auto-save") === true){
|
||||||
$this->server->schedule(18000, array($this, "autoSave"), array(), true);
|
$this->server->schedule(18000, array($this, "autoSave"), array(), true);
|
||||||
}
|
}
|
||||||
if($this->getProperty("enable-rcon") === true){
|
if(!defined("NO_THREADS") and $this->getProperty("enable-rcon") === true){
|
||||||
$this->rcon = new RCON($this->getProperty("rcon.password", ""), $this->getProperty("rcon.port", $this->getProperty("server-port")), ($ip = $this->getProperty("server-ip")) != "" ? $ip:"0.0.0.0", $this->getProperty("rcon.threads", 1), $this->getProperty("rcon.clients-per-thread", 50));
|
$this->rcon = new RCON($this->getProperty("rcon.password", ""), $this->getProperty("rcon.port", $this->getProperty("server-port")), ($ip = $this->getProperty("server-ip")) != "" ? $ip:"0.0.0.0", $this->getProperty("rcon.threads", 1), $this->getProperty("rcon.clients-per-thread", 50));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
38
src/tests/ServerSuiteTest.php
Normal file
38
src/tests/ServerSuiteTest.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
if(class_exists("PHPUnit_Framework_TestCase", false)){
|
||||||
|
|
||||||
|
class ServerSuiteTest extends PHPUnit_Framework_TestCase{
|
||||||
|
private $server;
|
||||||
|
public function hook(){
|
||||||
|
$this->assertTrue(true);
|
||||||
|
$server = ServerAPI::request();
|
||||||
|
|
||||||
|
|
||||||
|
//Everything done!
|
||||||
|
$server->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testRead(){
|
||||||
|
define("NO_THREADS", true);
|
||||||
|
require_once(dirname(__FILE__)."/../dependencies.php");
|
||||||
|
require_once(FILE_PATH."/src/functions.php");
|
||||||
|
require_once(FILE_PATH."/src/dependencies.php");
|
||||||
|
|
||||||
|
//binary things
|
||||||
|
$this->assertTrue(Utils::readTriad("\x02\x01\x03") === 131331, "Utils::readTriad");
|
||||||
|
$this->assertTrue(Utils::readInt("\xff\x02\x01\x03") === -16645885, "Utils::readInt");
|
||||||
|
$this->assertTrue(abs(Utils::readFloat("\x49\x02\x01\x03") - 532496.1875) < 0.0001, "Utils::readFloat");
|
||||||
|
$this->assertTrue(abs(Utils::readDouble("\x41\x02\x03\x04\x05\x06\x07\x08") - 147552.5024529) < 0.0001, "Utils::readDouble");
|
||||||
|
$this->assertTrue(Utils::readLong("\x41\x02\x03\x04\x05\x06\x07\x08") === "4684309878217770760", "Utils::readLong");
|
||||||
|
|
||||||
|
//PocketMine-MP server startup
|
||||||
|
$this->server = new ServerAPI();
|
||||||
|
$this->server->load();
|
||||||
|
$this->assertTrue(is_integer($this->server->event("server.start", array($this, "hook"))));
|
||||||
|
$this->server->init();
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
6
src/tests/phpunit.xml
Normal file
6
src/tests/phpunit.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<phpunit>
|
||||||
|
<testsuite name='PocketMine-MP'>
|
||||||
|
<directory suffix='.php'>./</directory>
|
||||||
|
</testsuite>
|
||||||
|
</phpunit>
|
Loading…
x
Reference in New Issue
Block a user