From e0c31dda754c7349f19efc5d57f8eeba0a5de59d Mon Sep 17 00:00:00 2001 From: Tom Graham Date: Mon, 24 Oct 2016 12:01:08 +0100 Subject: [PATCH] Fix issue with incompatible backups causing fatal errors when trying to rollback. --- src/Patch/Backup/BackupFinder.php | 3 +++ tests/Patch/Backup/BackupFinderTest.php | 31 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/Patch/Backup/BackupFinder.php b/src/Patch/Backup/BackupFinder.php index 0115585b..299362c8 100644 --- a/src/Patch/Backup/BackupFinder.php +++ b/src/Patch/Backup/BackupFinder.php @@ -7,6 +7,7 @@ use Meteor\Configuration\Exception\ConfigurationLoadingException; use Meteor\Package\PackageConstants; use Meteor\Patch\Version\VersionComparer; +use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; class BackupFinder { @@ -67,6 +68,8 @@ public function find($installDir, array $config) } } catch (ConfigurationLoadingException $exception) { // Not a valid backup + } catch (InvalidConfigurationException $exception) { + // Unable to parse config } } diff --git a/tests/Patch/Backup/BackupFinderTest.php b/tests/Patch/Backup/BackupFinderTest.php index e9cf35a9..904b9f0f 100644 --- a/tests/Patch/Backup/BackupFinderTest.php +++ b/tests/Patch/Backup/BackupFinderTest.php @@ -5,6 +5,7 @@ use Meteor\Configuration\Exception\ConfigurationLoadingException; use Meteor\Patch\Version\VersionComparer; use Mockery; +use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; use org\bovigo\vfs\vfsStream; class BackupFinderTest extends \PHPUnit_Framework_TestCase @@ -95,6 +96,36 @@ public function testFindIgnoresBackupsWithoutMeteorConfig() $this->assertCount(0, $backups); } + public function testFindIgnoresBackupsWithAnInvalidMeteorConfig() + { + $config = array( + 'name' => 'jadu/cms', + 'package' => array( + 'version' => 'VERSION', + ), + ); + + vfsStream::setup('root', null, array( + 'backups' => array( + '20160701102030' => array( + 'to_patch' => array( + 'VERSION' => '1.0.0', + ), + ), + ), + 'VERSION' => '1.1.0', + )); + + $this->configurationLoader->shouldReceive('load') + ->with(vfsStream::url('root/backups/20160701102030')) + ->andThrow(new InvalidConfigurationException()) + ->once(); + + $backups = $this->backupFinder->find(vfsStream::url('root'), $config); + + $this->assertCount(0, $backups); + } + public function testFindWithCombinedPackages() { $config = array(