mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-05 01:29:55 +00:00
Custom unit test code.
This commit is contained in:
parent
251859921d
commit
ad1930da88
@ -7,7 +7,7 @@ before_script:
|
|||||||
- pecl install channel://pecl.php.net/pthreads-0.0.44
|
- pecl install channel://pecl.php.net/pthreads-0.0.44
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- phpunit --process-isolation --configuration phpunit.xml
|
- php src/tests/ServerSuiteTest.php
|
||||||
|
|
||||||
notifications:
|
notifications:
|
||||||
email: false
|
email: false
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
<phpunit backupGlobals="false" backupStaticAttributes="false" syntaxCheck="true">
|
|
||||||
<testsuites>
|
|
||||||
<testsuite name="PocketMine-MP">
|
|
||||||
<directory suffix=".php">src/tests</directory>
|
|
||||||
</testsuite>
|
|
||||||
</testsuites>
|
|
||||||
</phpunit>
|
|
@ -20,10 +20,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/***REM_START***/
|
/***REM_START***/
|
||||||
if(!class_exists("PHPUnit_Framework_TestCase", false)){
|
|
||||||
class PHPUnit_Framework_TestCase{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
require_once(dirname(__FILE__)."/config.php");
|
require_once(dirname(__FILE__)."/config.php");
|
||||||
require_once(FILE_PATH."/src/functions.php");
|
require_once(FILE_PATH."/src/functions.php");
|
||||||
/***REM_END***/
|
/***REM_END***/
|
||||||
|
@ -1,30 +1,53 @@
|
|||||||
<?php
|
<?php
|
||||||
/***REM_START***/
|
/***REM_START***/
|
||||||
|
$testErrors = 0;
|
||||||
class ServerSuiteTest extends PHPUnit_Framework_TestCase{
|
function testCase($name, $output, $expected){
|
||||||
public function testStart(){
|
global $testErrors;
|
||||||
define("NO_THREADS", true);
|
if($output === $expected){
|
||||||
define("DEBUG", -1); //No output
|
console("[TEST] $name: \x1b[32mOk.");
|
||||||
require_once(dirname(__FILE__)."/../dependencies.php");
|
}else{
|
||||||
require_once(FILE_PATH."/src/functions.php");
|
console("[TEST] $name: \x1b[31mError.");
|
||||||
require_once(FILE_PATH."/src/dependencies.php");
|
console("Expected ".safe_var_dump($expected).", got ".$output);
|
||||||
|
++$testErrors;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!class_exists("PocketMinecraftServer", false)){
|
||||||
|
define("NO_THREADS", true);
|
||||||
|
require_once(dirname(__FILE__)."/../dependencies.php");
|
||||||
|
require_once(FILE_PATH."/src/functions.php");
|
||||||
|
require_once(FILE_PATH."/src/dependencies.php");
|
||||||
|
console("\x1b[36m[TEST] Starting tests");
|
||||||
|
$t = new ServerSuiteTest;
|
||||||
|
echo PHP_EOL;
|
||||||
|
if($testErrors === 0){
|
||||||
|
console("\x1b[32m[TEST] No errors. Test complete.");
|
||||||
|
exit(0);
|
||||||
|
}else{
|
||||||
|
console("\x1b[31m[TEST] Errors found.");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ServerSuiteTest {
|
||||||
|
public function __construct(){
|
||||||
//binary things
|
//binary things
|
||||||
$this->assertTrue(Utils::readTriad("\x02\x01\x03") === 131331, "Utils::readTriad");
|
testCase("Utils::readTriad", Utils::readTriad("\x02\x01\x03"), 131331);
|
||||||
$this->assertTrue(Utils::readInt("\xff\x02\x01\x03") === -16645885, "Utils::readInt");
|
testCase("Utils::readInt", Utils::readInt("\xff\x02\x01\x03"), -16645885);
|
||||||
$this->assertTrue(abs(Utils::readFloat("\x49\x02\x01\x03") - 532496.1875) < 0.0001, "Utils::readFloat");
|
testCase("Utils::readFloat", abs(Utils::readFloat("\x49\x02\x01\x03") - 532496.1875) < 0.0001, true);
|
||||||
$this->assertTrue(abs(Utils::readDouble("\x41\x02\x03\x04\x05\x06\x07\x08") - 147552.5024529) < 0.0001, "Utils::readDouble");
|
testCase("Utils::readDouble", abs(Utils::readDouble("\x41\x02\x03\x04\x05\x06\x07\x08") - 147552.5024529) < 0.0001, true);
|
||||||
$this->assertTrue(Utils::readLong("\x41\x02\x03\x04\x05\x06\x07\x08") === "4684309878217770760", "Utils::readLong");
|
testCase("Utils::readTriad", Utils::readLong("\x41\x02\x03\x04\x05\x06\x07\x08"), "4684309878217770760");
|
||||||
|
|
||||||
//PocketMine-MP server startup
|
//PocketMine-MP server startup
|
||||||
global $server;
|
global $server;
|
||||||
$server = new ServerAPI();
|
$server = new ServerAPI();
|
||||||
$server->load();
|
$server->load();
|
||||||
$this->assertTrue(is_integer($server->event("server.start", array($this, "hook"))));
|
testCase("event attached", is_integer($server->event("server.start", array($this, "hook"))), true);
|
||||||
$server->init();
|
$server->init();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hook(){
|
public function hook(){
|
||||||
|
testCase("event fired", true, true);
|
||||||
//Everything done!
|
//Everything done!
|
||||||
ServerAPI::request()->close();
|
ServerAPI::request()->close();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user