From a24d50d7e37e245dc16da3ecd3a93b92c7956c03 Mon Sep 17 00:00:00 2001 From: Pierre Goiffon Date: Fri, 11 Aug 2023 15:19:48 +0200 Subject: [PATCH] :white_check_mark: DBBackupDataTest::testPrepareFilesToBackup : fix cleanup not done on failing test --- .../unitary-tests/setup/DBBackupDataTest.php | 46 +++++++++---------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/tests/php-unit-tests/unitary-tests/setup/DBBackupDataTest.php b/tests/php-unit-tests/unitary-tests/setup/DBBackupDataTest.php index 02ec0734a..78c8dfbbd 100644 --- a/tests/php-unit-tests/unitary-tests/setup/DBBackupDataTest.php +++ b/tests/php-unit-tests/unitary-tests/setup/DBBackupDataTest.php @@ -32,35 +32,33 @@ class DBBackupDataTest extends ItopDataTestCase file_put_contents(APPROOT.'/'.$sExtraFile, 'Hello World!'); } } - - if ($bUnsafeFileException) - { - $this->expectExceptionMessage("Backup: Aborting, resource '$sExtraFile'. Considered as UNSAFE because not inside the iTop directory."); - } - $aFiles = $this->InvokeNonPublicMethod('DBBackup', 'PrepareFilesToBackup', $oBackup, [APPROOT.'/conf/production/config-itop.php', $sTmpDir, true]); - SetupUtils::rrmdir($sTmpDir); - $aExpectedFiles = [ - $sTmpDir.'/config-itop.php', - ]; - foreach($aExtraFiles as $sRelFile => $bExists) - { - if ($bExists) - { - $aExpectedFiles[] = $sTmpDir.'/'.$sRelFile; + + try { + if ($bUnsafeFileException) { + $this->expectExceptionMessage("Backup: Aborting, resource '$sExtraFile'. Considered as UNSAFE because not inside the iTop directory."); + } + $aFiles = $this->InvokeNonPublicMethod('DBBackup', 'PrepareFilesToBackup', $oBackup, [APPROOT . '/conf/production/config-itop.php', $sTmpDir, true]); + SetupUtils::rrmdir($sTmpDir); + $aExpectedFiles = [ + $sTmpDir . '/config-itop.php', + ]; + foreach ($aExtraFiles as $sRelFile => $bExists) { + if ($bExists) { + $aExpectedFiles[] = $sTmpDir . '/' . $sRelFile; + } + } + } finally { + // Cleanup + foreach ($aExtraFiles as $sExtraFile => $bExists) { + if ($bExists) { + unlink(APPROOT . '/' . $sExtraFile); + } } } + sort($aFiles); sort($aExpectedFiles); $this->assertEquals($aFiles, $aExpectedFiles); - - // Cleanup - foreach($aExtraFiles as $sExtraFile => $bExists) - { - if ($bExists) - { - unlink(APPROOT.'/'.$sExtraFile); - } - } } function prepareFilesToBackupProvider()