Started PHPUnit Tests
This commit is contained in:
parent
19c500c105
commit
eb6dc3db1a
15
Tests/core/LoggerTest.php
Normal file
15
Tests/core/LoggerTest.php
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: Lukas
|
||||||
|
* Date: 14. Apr. 2017
|
||||||
|
* Time: 22:41
|
||||||
|
*/
|
||||||
|
|
||||||
|
use ManiaControl\Logger;
|
||||||
|
|
||||||
|
class LoggerTest extends PHPUnit_Framework_TestCase {
|
||||||
|
public function testGetLogsFolder(){
|
||||||
|
$this->assertEquals(Logger::getLogsFolder(), MANIACONTROL_PATH . 'logs' . DIRECTORY_SEPARATOR);
|
||||||
|
}
|
||||||
|
}
|
23
Tests/core/ManiaControlTest.php
Normal file
23
Tests/core/ManiaControlTest.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use ManiaControl\ManiaControl;
|
||||||
|
|
||||||
|
class ManiaControlTest extends PHPUnit_Framework_TestCase {
|
||||||
|
public function testRun(){
|
||||||
|
$maniaControl = new ManiaControl();
|
||||||
|
$maniaControl->run(10);
|
||||||
|
|
||||||
|
sleep(15);
|
||||||
|
|
||||||
|
//$this->l
|
||||||
|
//$this->assertNull($maniaControl);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* public function testGetClient(){
|
||||||
|
$maniaControl = new ManiaControl();
|
||||||
|
$mcClient = $maniaControl->getClient();
|
||||||
|
|
||||||
|
//$maniaControl->connect();
|
||||||
|
//$mpClient = new Maniaplanet\DedicatedServer\Connection();
|
||||||
|
}*/
|
||||||
|
}
|
70
Tests/core/Update/UpdateManagerTest.php
Normal file
70
Tests/core/Update/UpdateManagerTest.php
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\core\Update;
|
||||||
|
|
||||||
|
|
||||||
|
use ManiaControl\ManiaControl;
|
||||||
|
use ManiaControl\Update\UpdateManager;
|
||||||
|
|
||||||
|
final class UpdateManagerTest extends \PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
|
public function testBuildDate() {
|
||||||
|
$maniaControl = new ManiaControl();
|
||||||
|
$updateManager = new UpdateManager($maniaControl);
|
||||||
|
|
||||||
|
$fileName = MANIACONTROL_PATH . "core" . DIRECTORY_SEPARATOR . UpdateManager::BUILD_DATE_FILE_NAME;
|
||||||
|
|
||||||
|
if(!file_exists($fileName)){
|
||||||
|
$this->assertTrue($updateManager->setBuildDate("BuildDateTest-6543210"));
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertFileExists($fileName);
|
||||||
|
|
||||||
|
$buildDate = $updateManager->getBuildDate();
|
||||||
|
$this->assertStringEqualsFile($fileName, $buildDate);
|
||||||
|
|
||||||
|
$this->assertTrue($updateManager->setBuildDate("BuildDateTest-0123456"));
|
||||||
|
$this->assertEquals($updateManager->getBuildDate(), "BuildDateTest-0123456");
|
||||||
|
|
||||||
|
$this->assertStringEqualsFile($fileName, $updateManager->getBuildDate());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetPluginUpdateManagerTest() {
|
||||||
|
$maniaControl = new ManiaControl();
|
||||||
|
$updateManager = new UpdateManager($maniaControl);
|
||||||
|
|
||||||
|
$pluginUpdateManager = $updateManager->getPluginUpdateManager();
|
||||||
|
|
||||||
|
$this->assertInstanceOf("ManiaControl\\Update\\PluginUpdateManager", $pluginUpdateManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIsNightlyUpdateChannel() {
|
||||||
|
$maniaControl = new ManiaControl();
|
||||||
|
$updateManager = new UpdateManager($maniaControl);
|
||||||
|
|
||||||
|
$this->assertTrue($updateManager->isNightlyUpdateChannel(UpdateManager::CHANNEL_NIGHTLY));
|
||||||
|
|
||||||
|
$isNightly = $updateManager->isNightlyUpdateChannel(null);
|
||||||
|
|
||||||
|
$this->assertEquals($updateManager->isNightlyUpdateChannel($updateManager->getCurrentUpdateChannelSetting()), $isNightly);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCoreUpdateAsync() {
|
||||||
|
$maniaControl = new ManiaControl();
|
||||||
|
|
||||||
|
$updateManager = $maniaControl->getUpdateManager();
|
||||||
|
|
||||||
|
$called = false;
|
||||||
|
$function = function ($updateData) use (&$called){
|
||||||
|
$called = true;
|
||||||
|
$this->assertNotNull($updateData);
|
||||||
|
$this->assertObjectHasAttribute("version", $updateData);
|
||||||
|
};
|
||||||
|
|
||||||
|
$updateManager->checkCoreUpdateAsync($function);
|
||||||
|
|
||||||
|
$maniaControl->run(6);
|
||||||
|
|
||||||
|
$this->assertTrue($called);
|
||||||
|
}
|
||||||
|
}
|
@ -166,6 +166,8 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener,
|
|||||||
|
|
||||||
private $requestQuitMessage = null;
|
private $requestQuitMessage = null;
|
||||||
|
|
||||||
|
private $startTime = -1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new ManiaControl instance
|
* Construct a new ManiaControl instance
|
||||||
*/
|
*/
|
||||||
@ -547,11 +549,12 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener,
|
|||||||
$this->requestQuitMessage = $message;
|
$this->requestQuitMessage = $message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run ManiaControl
|
* Run ManiaControl
|
||||||
|
*
|
||||||
|
* @param int $runTime Time in Seconds until its terminating (used for PHPUnit Tests)
|
||||||
*/
|
*/
|
||||||
public function run() {
|
public function run($runTime = -1) {
|
||||||
Logger::log('Starting ManiaControl v' . self::VERSION . '!');
|
Logger::log('Starting ManiaControl v' . self::VERSION . '!');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -583,14 +586,22 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener,
|
|||||||
Logger::log('Link: ' . $this->getServer()->getJoinLink());
|
Logger::log('Link: ' . $this->getServer()->getJoinLink());
|
||||||
$this->getChat()->sendInformation('ManiaControl v' . self::VERSION . ' successfully started!');
|
$this->getChat()->sendInformation('ManiaControl v' . self::VERSION . ' successfully started!');
|
||||||
|
|
||||||
|
$this->startTime = time();
|
||||||
|
|
||||||
// Main loop
|
// Main loop
|
||||||
while (!$this->requestQuitMessage) {
|
while (!$this->requestQuitMessage) {
|
||||||
$this->loop();
|
$this->loop();
|
||||||
|
|
||||||
|
//Used for PHPUnit Tests
|
||||||
|
if ($runTime > 0) {
|
||||||
|
if (time() > ($this->startTime + $runTime)) {
|
||||||
|
$this->requestQuit("Run Time Exceeded");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shutdown
|
// Shutdown
|
||||||
$this->quit($this->requestQuitMessage);
|
$this->quit($this->requestQuitMessage);
|
||||||
|
|
||||||
} catch (TransportException $exception) {
|
} catch (TransportException $exception) {
|
||||||
Logger::logError('Connection interrupted!');
|
Logger::logError('Connection interrupted!');
|
||||||
$this->getErrorHandler()->handleException($exception);
|
$this->getErrorHandler()->handleException($exception);
|
||||||
@ -679,7 +690,9 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener,
|
|||||||
$loopStart = microtime(true);
|
$loopStart = microtime(true);
|
||||||
|
|
||||||
// Extend script timeout
|
// Extend script timeout
|
||||||
|
if(!defined('PHP_UNIT_TEST')){
|
||||||
set_time_limit(self::SCRIPT_TIMEOUT);
|
set_time_limit(self::SCRIPT_TIMEOUT);
|
||||||
|
}
|
||||||
|
|
||||||
// Manage callbacks
|
// Manage callbacks
|
||||||
$this->getCallbackManager()->manageCallbacks();
|
$this->getCallbackManager()->manageCallbacks();
|
||||||
|
@ -145,6 +145,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
|||||||
Logger::logError('Error on UpdateCheck: ' . $error);
|
Logger::logError('Error on UpdateCheck: ' . $error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$versions = json_decode($dataJson);
|
$versions = json_decode($dataJson);
|
||||||
if (!$versions || !isset($versions[0])) {
|
if (!$versions || !isset($versions[0])) {
|
||||||
call_user_func($function);
|
call_user_func($function);
|
||||||
|
@ -117,8 +117,11 @@ class SystemUtil {
|
|||||||
Logger::log($message);
|
Logger::log($message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!defined('PHP_UNIT_TEST')) {
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Restart ManiaControl immediately
|
* Restart ManiaControl immediately
|
||||||
|
Loading…
Reference in New Issue
Block a user