Custom unit test code.

This commit is contained in:
Shoghi Cervantes 2013-08-28 18:19:48 +02:00
parent 251859921d
commit ad1930da88
4 changed files with 40 additions and 28 deletions

View File

@ -7,7 +7,7 @@ before_script:
- pecl install channel://pecl.php.net/pthreads-0.0.44
script:
- phpunit --process-isolation --configuration phpunit.xml
- php src/tests/ServerSuiteTest.php
notifications:
email: false

View File

@ -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>

View File

@ -20,10 +20,6 @@
*/
/***REM_START***/
if(!class_exists("PHPUnit_Framework_TestCase", false)){
class PHPUnit_Framework_TestCase{
}
}
require_once(dirname(__FILE__)."/config.php");
require_once(FILE_PATH."/src/functions.php");
/***REM_END***/

View File

@ -1,30 +1,53 @@
<?php
/***REM_START***/
class ServerSuiteTest extends PHPUnit_Framework_TestCase{
public function testStart(){
define("NO_THREADS", true);
define("DEBUG", -1); //No output
require_once(dirname(__FILE__)."/../dependencies.php");
require_once(FILE_PATH."/src/functions.php");
require_once(FILE_PATH."/src/dependencies.php");
$testErrors = 0;
function testCase($name, $output, $expected){
global $testErrors;
if($output === $expected){
console("[TEST] $name: \x1b[32mOk.");
}else{
console("[TEST] $name: \x1b[31mError.");
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
$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");
testCase("Utils::readTriad", Utils::readTriad("\x02\x01\x03"), 131331);
testCase("Utils::readInt", Utils::readInt("\xff\x02\x01\x03"), -16645885);
testCase("Utils::readFloat", abs(Utils::readFloat("\x49\x02\x01\x03") - 532496.1875) < 0.0001, true);
testCase("Utils::readDouble", abs(Utils::readDouble("\x41\x02\x03\x04\x05\x06\x07\x08") - 147552.5024529) < 0.0001, true);
testCase("Utils::readTriad", Utils::readLong("\x41\x02\x03\x04\x05\x06\x07\x08"), "4684309878217770760");
//PocketMine-MP server startup
global $server;
$server = new ServerAPI();
$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();
}
public function hook(){
public function hook(){
testCase("event fired", true, true);
//Everything done!
ServerAPI::request()->close();
}