From 070e9ebbae7e8bfc11c405082112cd5884ad8af5 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 28 Aug 2013 14:20:29 +0200 Subject: [PATCH 1/8] Removed tests building --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index c3cf74e63..7e07f39a5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,3 +13,7 @@ script: notifications: email: false webhooks: http://n.tkte.ch/h/214/wsNvmG43-ncxUVRrFPwSM-r0 + +branches: + except: + - tests \ No newline at end of file From 4d53d07def431ef763d15c02785e749907067112 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 28 Aug 2013 15:24:18 +0200 Subject: [PATCH 2/8] Moved tests --- .travis.yml | 9 ++------- src/tests/ServerSuiteTest.php | 30 ++++++++++++++++++++++++++++++ src/tests/phpunit.xml | 6 ++++++ 3 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 src/tests/ServerSuiteTest.php create mode 100644 src/tests/phpunit.xml diff --git a/.travis.yml b/.travis.yml index 7e07f39a5..6c4cc8038 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,15 +5,10 @@ php: before_script: - 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: - - phpunit tests/ + - phpunit src/tests/ notifications: email: false - webhooks: http://n.tkte.ch/h/214/wsNvmG43-ncxUVRrFPwSM-r0 - -branches: - except: - - tests \ No newline at end of file + webhooks: http://n.tkte.ch/h/214/wsNvmG43-ncxUVRrFPwSM-r0 \ No newline at end of file diff --git a/src/tests/ServerSuiteTest.php b/src/tests/ServerSuiteTest.php new file mode 100644 index 000000000..9389ac920 --- /dev/null +++ b/src/tests/ServerSuiteTest.php @@ -0,0 +1,30 @@ +assertTrue(true); + + $this->server->close(); + } + + public function testRead(){ + + //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 + require_once(dirname(__FILE__)."/../dependencies.php"); + require_once(FILE_PATH."/src/functions.php"); + require_once(FILE_PATH."/src/dependencies.php"); + $this->server = new ServerAPI(); + $this->assertTrue(is_integer($this->server->event("server.start", array($this, "hook")))); + $this->server->start(); + + kill(getmypid()); //Fix for ConsoleAPI being blocked + exit(0); + } +} \ No newline at end of file diff --git a/src/tests/phpunit.xml b/src/tests/phpunit.xml new file mode 100644 index 000000000..2fa40761e --- /dev/null +++ b/src/tests/phpunit.xml @@ -0,0 +1,6 @@ + + + + ./ + + \ No newline at end of file From ff4970578a5e5a4c3d6a810b1ef1ccf25825b99a Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 28 Aug 2013 15:27:24 +0200 Subject: [PATCH 3/8] Moved requires() --- src/tests/ServerSuiteTest.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/tests/ServerSuiteTest.php b/src/tests/ServerSuiteTest.php index 9389ac920..7b9a4f756 100644 --- a/src/tests/ServerSuiteTest.php +++ b/src/tests/ServerSuiteTest.php @@ -9,6 +9,9 @@ class ServerSuiteTest extends PHPUnit_Framework_TestCase{ } public function testRead(){ + 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"); @@ -16,10 +19,8 @@ class ServerSuiteTest extends PHPUnit_Framework_TestCase{ $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 - require_once(dirname(__FILE__)."/../dependencies.php"); - require_once(FILE_PATH."/src/functions.php"); - require_once(FILE_PATH."/src/dependencies.php"); $this->server = new ServerAPI(); $this->assertTrue(is_integer($this->server->event("server.start", array($this, "hook")))); $this->server->start(); From 56fdc87e9b00702f6feebc049026a7fdc0edef2e Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 28 Aug 2013 15:32:16 +0200 Subject: [PATCH 4/8] Changed automatic init to manual startup --- src/tests/ServerSuiteTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/tests/ServerSuiteTest.php b/src/tests/ServerSuiteTest.php index 7b9a4f756..27e3f4d51 100644 --- a/src/tests/ServerSuiteTest.php +++ b/src/tests/ServerSuiteTest.php @@ -22,8 +22,9 @@ class ServerSuiteTest extends PHPUnit_Framework_TestCase{ //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->start(); + $this->server->init(); kill(getmypid()); //Fix for ConsoleAPI being blocked exit(0); From 8dcb404bce6f2a0e703a54270467acbdc9ea7f62 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 28 Aug 2013 15:36:14 +0200 Subject: [PATCH 5/8] Correct server object --- src/tests/ServerSuiteTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/tests/ServerSuiteTest.php b/src/tests/ServerSuiteTest.php index 27e3f4d51..9701b621e 100644 --- a/src/tests/ServerSuiteTest.php +++ b/src/tests/ServerSuiteTest.php @@ -4,8 +4,11 @@ class ServerSuiteTest extends PHPUnit_Framework_TestCase{ private $server; public function hook(){ $this->assertTrue(true); + $server = ServerAPI::request(); - $this->server->close(); + + //Everything done! + $server->close(); } public function testRead(){ From a07ae731e3b4e72efc4b4d68eb46f567009b9548 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 28 Aug 2013 15:45:15 +0200 Subject: [PATCH 6/8] Removed self-kill [will it blend?] --- src/tests/ServerSuiteTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/tests/ServerSuiteTest.php b/src/tests/ServerSuiteTest.php index 9701b621e..7338a2212 100644 --- a/src/tests/ServerSuiteTest.php +++ b/src/tests/ServerSuiteTest.php @@ -28,8 +28,6 @@ class ServerSuiteTest extends PHPUnit_Framework_TestCase{ $this->server->load(); $this->assertTrue(is_integer($this->server->event("server.start", array($this, "hook")))); $this->server->init(); - - kill(getmypid()); //Fix for ConsoleAPI being blocked exit(0); } } \ No newline at end of file From f9c405d46ac16782e00ef698753cf4cc08ffbbc6 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 28 Aug 2013 16:00:30 +0200 Subject: [PATCH 7/8] NO_THREADS mode for tests --- src/API/ConsoleAPI.php | 15 +++++++++++---- src/API/ServerAPI.php | 2 +- src/tests/ServerSuiteTest.php | 1 + 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/API/ConsoleAPI.php b/src/API/ConsoleAPI.php index e60b2e5c5..e74a68dad 100644 --- a/src/API/ConsoleAPI.php +++ b/src/API/ConsoleAPI.php @@ -31,7 +31,9 @@ class ConsoleAPI{ public function init(){ $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("status", "", array($this, "defaultCommands")); $this->register("difficulty", "<0|1|2|3>", array($this, "defaultCommands")); @@ -42,9 +44,11 @@ class ConsoleAPI{ function __destruct(){ $this->server->deleteEvent($this->event); - $this->loop->stop(); - $this->loop->notify(); - //$this->loop->join(); + if(!defined("NO_THREADS")){ + $this->loop->stop(); + $this->loop->notify(); + //$this->loop->join(); + } } public function defaultCommands($cmd, $params, $issuer, $alias){ @@ -248,6 +252,9 @@ class ConsoleAPI{ } public function handle($time){ + if(defined("NO_THREADS")){ + return; + } if($this->loop->line !== false){ $line = trim($this->loop->line); $this->loop->line = false; diff --git a/src/API/ServerAPI.php b/src/API/ServerAPI.php index 157994dbe..54f8cd3ba 100644 --- a/src/API/ServerAPI.php +++ b/src/API/ServerAPI.php @@ -281,7 +281,7 @@ class ServerAPI{ if($this->getProperty("auto-save") === 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)); } diff --git a/src/tests/ServerSuiteTest.php b/src/tests/ServerSuiteTest.php index 7338a2212..069576c4b 100644 --- a/src/tests/ServerSuiteTest.php +++ b/src/tests/ServerSuiteTest.php @@ -12,6 +12,7 @@ class ServerSuiteTest extends PHPUnit_Framework_TestCase{ } 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"); From 13a5a8df5754e3e8e216aa4149db2b4713de28b3 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 28 Aug 2013 16:07:53 +0200 Subject: [PATCH 8/8] Check phpunit classes --- src/tests/ServerSuiteTest.php | 60 +++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/src/tests/ServerSuiteTest.php b/src/tests/ServerSuiteTest.php index 069576c4b..aa9382147 100644 --- a/src/tests/ServerSuiteTest.php +++ b/src/tests/ServerSuiteTest.php @@ -1,34 +1,38 @@ assertTrue(true); - $server = ServerAPI::request(); +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"); - - //Everything done! - $server->close(); + //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); + } } - 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); - } } \ No newline at end of file