/** * Executes restore for given event. * * @param RestoreEvent $event */ public function onRestore(RestoreEvent $event) { $plugin = $this->pluginRegistry->getPlugin($event->getOption('plugin')); $optionsResolver = new OptionsResolver(); $plugin->configureOptionsResolver($optionsResolver); $parameter = $optionsResolver->resolve($event->getOption('parameter')); try { $plugin->restore($event->getSource(), $event->getDestination(), $event->getDatabase(), $parameter); $event->setStatus(BackupStatus::STATE_SUCCESS); } catch (\Exception $exception) { $event->setStatus(BackupStatus::STATE_FAILED); $event->setException($exception); } }
/** * Check single backup-configuration. * * @param PluginRegistry $plugins * @param SymfonyStyle $io * @param string $name * @param array $backup * * @return bool */ private function checkBackup(PluginRegistry $plugins, SymfonyStyle $io, $name, array $backup) { $io->section('Backup: ' . $name); if (!$plugins->has($backup['plugin'])) { $io->warning(sprintf('Plugin "%s" not found', $backup['plugin'])); return false; } $optionsResolver = new OptionsResolver(); $plugins->getPlugin($backup['plugin'])->configureOptionsResolver($optionsResolver); try { $parameter = $optionsResolver->resolve($backup['parameter']); } catch (InvalidArgumentException $e) { $io->warning(sprintf('Parameter not valid' . PHP_EOL . PHP_EOL . 'Message: "%s"', $e->getMessage())); return false; } $io->write('Parameter:'); $messages = array_filter(explode("\r\n", Yaml::dump($parameter))); $io->block($messages, null, null, ' '); $io->writeln('OK'); return true; }
public function testExecuteOKMultiple() { $plugin = $this->prophesize(PluginInterface::class); $plugin->configureOptionsResolver(Argument::type(OptionsResolver::class))->will(function ($args) { $args[0]->setRequired(['chmod', 'directory']); }); $this->plugins->has('my-plugin')->willReturn(true); $this->plugins->getPlugin('my-plugin')->willReturn($plugin->reveal()); $commandTester = $this->getCommandTester(true, ['test-1' => ['plugin' => 'my-plugin', 'parameter' => ['directory' => '/test', 'chmod' => 0777]], 'test-2' => ['plugin' => 'my-plugin', 'parameter' => ['directory' => '/test', 'chmod' => 0777]]]); $commandTester->execute([]); $this->assertRegExp('/test-1([-\\s]*)([^-]*)OK/', $commandTester->getDisplay()); $this->assertRegExp('/test-2([-\\s]*)([^-]*)OK/', $commandTester->getDisplay()); }
public function testOnRestoreFail() { $exception = $this->prophesize(\Exception::class); $this->event->getOption('parameter')->willReturn(['directory' => '/test']); $this->event->getOption('plugin')->willReturn('test'); $this->event->setStatus(BackupStatus::STATE_FAILED)->shouldBeCalled(); $this->event->setException($exception->reveal())->shouldBeCalled(); $source = $this->prophesize(Filesystem::class); $destination = $this->prophesize(Filesystem::class); $database = $this->prophesize(Database::class); $this->event->getSource()->willReturn($source->reveal()); $this->event->getDestination()->willReturn($destination->reveal()); $this->event->getDatabase()->willReturn($database->reveal()); $plugin = $this->prophesize(PluginInterface::class); $plugin->configureOptionsResolver(Argument::type(OptionsResolver::class))->will(function ($arguments) { /** @var OptionsResolver $optionResolver */ $optionsResolver = $arguments[0]; $optionsResolver->setRequired('directory'); }); $plugin->restore($source->reveal(), $destination->reveal(), $database->reveal(), ['directory' => '/test'])->shouldBeCalled()->willThrow($exception->reveal()); $this->pluginRegistry->getPlugin('test')->willReturn($plugin->reveal()); $this->listener->onRestore($this->event->reveal()); }
/** * @dataProvider provideHasData */ public function testHas($name, $expected) { $plugin = $this->prophesize(PluginInterface::class); $registry = new PluginRegistry(['directory' => $plugin->reveal()]); $this->assertEquals($expected, $registry->has($name)); }