Ejemplo n.º 1
0
 /**
  * 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);
     }
 }
Ejemplo n.º 2
0
 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());
 }