Skip to content

Commit

Permalink
chore(tests): UT for file backup service
Browse files Browse the repository at this point in the history
Signed-off-by: Rubén D <[email protected]>
  • Loading branch information
nuxsmin committed Nov 13, 2023
1 parent 3dd1966 commit 2d56422
Show file tree
Hide file tree
Showing 11 changed files with 365 additions and 257 deletions.
12 changes: 6 additions & 6 deletions lib/SP/Domain/Config/Ports/ConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
Expand Down Expand Up @@ -42,15 +42,15 @@ public function loadConfigFromFile(): ConfigDataInterface;
/**
* Guardar la configuración
*
* @param ConfigDataInterface $configData
* @param bool|null $backup
* @param ConfigDataInterface $configData
* @param bool|null $backup
*
* @return ConfigInterface
* @throws \SP\Infrastructure\File\FileException
* @throws FileException
*/
public function saveConfig(
ConfigDataInterface $configData,
?bool $backup = true
?bool $backup = true
): ConfigInterface;

/**
Expand All @@ -66,7 +66,7 @@ public function loadConfig(?bool $reload = false): ConfigDataInterface;
/**
* Returns a clone of the configuration data
*
* @return \SP\Domain\Config\Ports\ConfigDataInterface
* @return ConfigDataInterface
*/
public function getConfigData(): ConfigDataInterface;

Expand Down
7 changes: 4 additions & 3 deletions lib/SP/Domain/Export/Ports/BackupFilesInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
Expand All @@ -24,6 +24,7 @@

namespace SP\Domain\Export\Ports;

use SP\Core\Exceptions\CheckException;
use SP\Infrastructure\File\ArchiveHandlerInterface;
use SP\Infrastructure\File\FileHandlerInterface;

Expand All @@ -44,13 +45,13 @@ public function getDbBackupFileHandler(): FileHandlerInterface;

/**
* @return ArchiveHandlerInterface
* @throws \SP\Core\Exceptions\CheckException
* @throws CheckException
*/
public function getDbBackupArchiveHandler(): ArchiveHandlerInterface;

/**
* @return ArchiveHandlerInterface
* @throws \SP\Core\Exceptions\CheckException
* @throws CheckException
*/
public function getAppBackupArchiveHandler(): ArchiveHandlerInterface;

Expand Down
6 changes: 4 additions & 2 deletions lib/SP/Domain/Export/Ports/FileBackupServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
Expand All @@ -24,6 +24,8 @@

namespace SP\Domain\Export\Ports;

use SP\Domain\Common\Services\ServiceException;

/**
* Esta clase es la encargada de realizar la copia de sysPass.
*/
Expand All @@ -32,7 +34,7 @@ interface FileBackupServiceInterface
/**
* Realizar backup de la BBDD y aplicación.
*
* @throws \SP\Domain\Common\Services\ServiceException
* @throws ServiceException
*/
public function doBackup(string $backupPath = BACKUP_PATH, string $applicationPath = APP_ROOT): void;

Expand Down
27 changes: 14 additions & 13 deletions lib/SP/Domain/Export/Services/BackupFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
Expand Down Expand Up @@ -32,6 +32,7 @@
use SP\Infrastructure\File\ArchiveHandlerInterface;
use SP\Infrastructure\File\FileHandler;
use SP\Infrastructure\File\FileHandlerInterface;

use function SP\__;
use function SP\__u;

Expand All @@ -46,14 +47,14 @@ final class BackupFiles implements BackupFilesInterface
private string $appBackupFilename;
private string $dbBackupFilename;
/**
* @var \SP\Core\PhpExtensionChecker
* @var PhpExtensionChecker
*/
private PhpExtensionChecker $extensionChecker;

/**
* @param string $path The path where to store the backup files
* @param string $path The path where to store the backup files
*
* @throws \SP\Core\Exceptions\CheckException
* @throws CheckException
*/
public function __construct(PhpExtensionChecker $extensionChecker, string $path = BACKUP_PATH)
{
Expand Down Expand Up @@ -103,12 +104,12 @@ private function checkBackupDir(): void
public static function getAppBackupFilename(
string $path,
string $hash,
bool $compressed = false
bool $compressed = false
): string {
$file = $path.DIRECTORY_SEPARATOR.AppInfoInterface::APP_NAME.'_app-'.$hash;
$file = $path . DIRECTORY_SEPARATOR . AppInfoInterface::APP_NAME . '_app-' . $hash;

if ($compressed) {
return $file.ArchiveHandler::COMPRESS_EXTENSION;
return $file . ArchiveHandler::COMPRESS_EXTENSION;
}

return $file;
Expand All @@ -117,15 +118,15 @@ public static function getAppBackupFilename(
public static function getDbBackupFilename(
string $path,
string $hash,
bool $compressed = false
bool $compressed = false
): string {
$file = $path.DIRECTORY_SEPARATOR.AppInfoInterface::APP_NAME.'_db-'.$hash;
$file = $path . DIRECTORY_SEPARATOR . AppInfoInterface::APP_NAME . '_db-' . $hash;

if ($compressed) {
return $file.ArchiveHandler::COMPRESS_EXTENSION;
return $file . ArchiveHandler::COMPRESS_EXTENSION;
}

return $file.'.sql';
return $file . '.sql';
}

/**
Expand All @@ -146,7 +147,7 @@ public function getDbBackupFileHandler(): FileHandlerInterface

/**
* @return ArchiveHandlerInterface
* @throws \SP\Core\Exceptions\CheckException
* @throws CheckException
*/
public function getDbBackupArchiveHandler(): ArchiveHandlerInterface
{
Expand All @@ -155,7 +156,7 @@ public function getDbBackupArchiveHandler(): ArchiveHandlerInterface

/**
* @return ArchiveHandlerInterface
* @throws \SP\Core\Exceptions\CheckException
* @throws CheckException
*/
public function getAppBackupArchiveHandler(): ArchiveHandlerInterface
{
Expand Down
Loading

0 comments on commit 2d56422

Please sign in to comment.