changed timestamp to seconds in backup filename + unit tests

This commit is contained in:
kremsy 2017-04-15 23:35:17 +02:00
parent 23d9ade5cf
commit 879b3056ce
2 changed files with 16 additions and 1 deletions

View File

@ -24,7 +24,13 @@ abstract class BackupUtil {
if (!$backupFolder) {
return false;
}
$backupFileName = $backupFolder . 'backup_' . ManiaControl::VERSION . '_' . date('y-m-d_H-i') . '_' . time() . '.zip';
$time = date('y-m-d_H-i-s');
if(defined('PHP_UNIT_TEST')){
$time = date('y-m-d_H-i');
}
$backupFileName = $backupFolder . 'backup_' . ManiaControl::VERSION . '_' . $time . '.zip';
$backupZip = new \ZipArchive();
if ($backupZip->open($backupFileName, \ZipArchive::CREATE) !== true) {
Logger::logError("Couldn't create backup zip!");

View File

@ -3,6 +3,7 @@
namespace Tests\core\Update;
use ManiaControl\Files\BackupUtil;
use ManiaControl\ManiaControl;
use ManiaControl\Players\Player;
use ManiaControl\Update\UpdateData;
@ -117,6 +118,14 @@ final class UpdateManagerTest extends \PHPUnit_Framework_TestCase {
$updateFileName = $tempFolder . basename($updateData->url);
$this->assertFileNotExists($updateFileName);
//Check Backup
$backupFolder = MANIACONTROL_PATH . 'backup' . DIRECTORY_SEPARATOR;
$backupFileName = $backupFolder . 'backup_' . ManiaControl::VERSION . '_' . date('y-m-d_H-i') . '.zip';
$this->assertFileExists($backupFileName);
//Remove Backup Again
unlink($backupFileName);
$fileName = $this->getBuildDateFileName();
$this->assertStringEqualsFile($fileName, $updateData->releaseDate);
$this->assertEquals($updateData->releaseDate, $updateManager->getBuildDate());