. */ namespace SP\Tests\Domain\Export\Services; use SP\Core\PhpExtensionChecker; use SP\Domain\Export\Services\BackupFiles; use SP\Domain\Export\Services\FileBackupService; use SP\Infrastructure\Database\Database; use SP\Infrastructure\Database\DatabaseUtil; use SP\Infrastructure\Database\MysqlHandler; use SP\Infrastructure\File\ArchiveHandler; use SP\Tests\UnitaryTestCase; /** * Class FileBackupServiceTest * * @package SP\Tests\Services\Backup */ class FileBackupServiceTest extends UnitaryTestCase { private FileBackupService $fileBackupService; /** * @throws \SP\Domain\Common\Services\ServiceException */ public function testDoBackup(): void { $this->fileBackupService->doBackup(TMP_PATH, APP_ROOT); } /** * @throws \SP\Core\Exceptions\ConfigException * @throws \SP\Core\Context\ContextException * @noinspection ClassMockingCorrectnessInspection * @noinspection PhpUnitInvalidMockingEntityInspection */ protected function setUp(): void { parent::setUp(); $database = $this->createStub(Database::class); $database->method('getDbHandler')->willReturn( $this->createStub(MysqlHandler::class) ); $archiveHandler = $this->createMock(ArchiveHandler::class); $archiveHandler->expects(self::once()) ->method('compressFile') ->withAnyParameters(); $archiveHandler->expects(self::once()) ->method('compressDirectory') ->with( APP_ROOT, FileBackupService::BACKUP_INCLUDE_REGEX ); $backupFiles = $this->getMockBuilder(BackupFiles::class) ->onlyMethods(['getDbBackupArchiveHandler', 'getAppBackupArchiveHandler']) ->setConstructorArgs([new PhpExtensionChecker()]) ->getMock(); $backupFiles->method('getDbBackupArchiveHandler')->willReturn($archiveHandler); $backupFiles->method('getAppBackupArchiveHandler')->willReturn($archiveHandler); $this->fileBackupService = new FileBackupService( $this->application, $database, $this->createStub(DatabaseUtil::class), $backupFiles ); } }