diff --git a/Tests/autoload.php b/Tests/autoload.php new file mode 100644 index 00000000..8f41edfe --- /dev/null +++ b/Tests/autoload.php @@ -0,0 +1,10 @@ +assertTrue($updateManager->setBuildDate("BuildDateTest-6543210")); } @@ -49,13 +51,13 @@ final class UpdateManagerTest extends \PHPUnit_Framework_TestCase { $this->assertEquals($updateManager->isNightlyUpdateChannel($updateManager->getCurrentUpdateChannelSetting()), $isNightly); } - public function testCoreUpdateAsync() { - $maniaControl = new ManiaControl(); + public function testCheckCoreUpdateAsync() { + $maniaControl = new ManiaControl(); $updateManager = $maniaControl->getUpdateManager(); - $called = false; - $function = function ($updateData) use (&$called){ + $called = false; + $function = function ($updateData) use (&$called) { $called = true; $this->assertNotNull($updateData); $this->assertObjectHasAttribute("version", $updateData); @@ -67,4 +69,38 @@ final class UpdateManagerTest extends \PHPUnit_Framework_TestCase { $this->assertTrue($called); } + + public function testPerformCoreUpdate() { + $maniaControl = new ManiaControl(); + $updateManager = $maniaControl->getUpdateManager(); + + //No Update Data Available -> so Fail + $this->assertFalse($updateManager->performCoreUpdate()); + + //Should Also Fail with a Player + $player = new Player($maniaControl, true); + $this->assertFalse($updateManager->performCoreUpdate($player)); + + $message = '[ERROR] Update failed: No update Data available!'; + $message = '[' . date('d-M-Y H:i:s e') . '] ' . $message . PHP_EOL; + + //Check message + $this->assertContains($message, $this->getActualOutput()); + + $dataJson = '[{"id":"260","version":"0.166","channel":"nightly","min_dedicated_build":"2014-04-02_18_00","release_date":"2017-03-16 21:57:40","url":"https:\/\/download.maniacontrol.com\/nightly\/ManiaControl_nightly_0-166.zip"}]'; + + //Create and Test Core Update Data + $updateData = new UpdateData(json_decode($dataJson)[0]); + + $this->assertEquals("0.166", $updateData->version); + $this->assertEquals("nightly", $updateData->channel); + $this->assertEquals("2014-04-02_18_00", $updateData->minDedicatedBuild); + $this->assertEquals("2017-03-16 21:57:40", $updateData->releaseDate); + $this->assertEquals("https://download.maniacontrol.com/nightly/ManiaControl_nightly_0-166.zip", $updateData->url); + + $updateManager->setCoreUpdateData($updateData); + + //Methods should return its non closure success + $this->assertTrue($updateManager->performCoreUpdate()); + } } diff --git a/Tests/phpunit.xml b/Tests/phpunit.xml new file mode 100644 index 00000000..7ead9864 --- /dev/null +++ b/Tests/phpunit.xml @@ -0,0 +1,25 @@ + + + + + Tests + + + + + ../core + + + + + + + + + + \ No newline at end of file diff --git a/core/Update/UpdateManager.php b/core/Update/UpdateManager.php index 02d30ea3..97e757dc 100644 --- a/core/Update/UpdateManager.php +++ b/core/Update/UpdateManager.php @@ -377,11 +377,13 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener return; } - $zip->extractTo(MANIACONTROL_PATH); - $zip->close(); - unlink($updateFileName); - FileUtil::deleteTempFolder(); - + if(!defined('PHP_UNIT_TEST')){ + $zip->extractTo(MANIACONTROL_PATH); + $zip->close(); + unlink($updateFileName); + FileUtil::deleteTempFolder(); + } + // Set the build date $this->setBuildDate($updateData->releaseDate);