Ejemplo n.º 1
0
 /**
  * @test
  *
  * @expectedException \RunOpenCode\Backup\Exception\EmptySourceException
  */
 public function emptySourceException()
 {
     $logger = new NullLogger();
     $eventDispatcher = new EventDispatcher();
     $fetchActivity = new Fetch();
     $profile = new Profile('test', new NullSource(), new NullProcessor(), new Constant('test'), new NullRotator(), new NullDestination(), new NullRotator(), Workflow::build($eventDispatcher, $logger));
     $fetchActivity->setLogger($logger);
     $fetchActivity->setEventDispatcher($eventDispatcher);
     $fetchActivity->setProfile($profile);
     $fetchActivity->setBackup(new Backup('test'));
     $fetchActivity->execute();
 }
Ejemplo n.º 2
0
 /**
  * @test
  */
 public function backup()
 {
     $logger = new NullLogger();
     $eventDispatcher = new EventDispatcher();
     $testResults = array();
     $eventDispatcher->addListener(BackupEvents::BEGIN, function (BackupEvent $event, $eventName) use(&$testResults) {
         $testResults[] = array('expected' => BackupEvents::BEGIN, 'actual' => $eventName, 'message' => 'Begin event should be dispatched');
     });
     $eventDispatcher->addListener(BackupEvents::FETCH, function (BackupEvent $event, $eventName) use(&$testResults) {
         $testResults[] = array('expected' => BackupEvents::FETCH, 'actual' => $eventName, 'message' => 'Fetch event should be dispatched');
         $testResults[] = array('expected' => 'my-profile', 'actual' => $event->getBackup()->getName(), 'message' => 'Backup name is profile name');
     });
     $eventDispatcher->addListener(BackupEvents::PROCESS, function (BackupEvent $event, $eventName) use(&$testResults) {
         $testResults[] = array('expected' => BackupEvents::PROCESS, 'actual' => $eventName, 'message' => 'Process event should be dispatched');
         $testResults[] = array('expected' => 1, 'actual' => count($event->getBackup()->getFiles()), 'message' => 'Should contain only one file');
         $testResults[] = array('expected' => 'archive.zip', 'actual' => $event->getBackup()->getFiles()[0]->getRelativePath(), 'message' => 'Should contain zip file with given name');
     });
     $eventDispatcher->addListener(BackupEvents::NAME, function (BackupEvent $event, $eventName) use(&$testResults) {
         $testResults[] = array('expected' => BackupEvents::NAME, 'actual' => $eventName, 'message' => 'Name event should be dispatched');
         $testResults[] = array('expected' => 'backup-application-test', 'actual' => $event->getBackup()->getName(), 'message' => 'Backup name is given name');
     });
     $eventDispatcher->addListener(BackupEvents::PRE_ROTATE, function (BackupEvent $event, $eventName) use(&$testResults) {
         $testResults[] = array('expected' => BackupEvents::PRE_ROTATE, 'actual' => $eventName, 'message' => 'Pre-rotate event should be dispatched');
     });
     $eventDispatcher->addListener(BackupEvents::POST_ROTATE, function (BackupEvent $event, $eventName) use(&$testResults) {
         $testResults[] = array('expected' => BackupEvents::POST_ROTATE, 'actual' => $eventName, 'message' => 'Post-rotate event should be dispatched');
     });
     $eventDispatcher->addListener(BackupEvents::PUSH, function (BackupEvent $event, $eventName) use(&$testResults) {
         $testResults[] = array('expected' => BackupEvents::PUSH, 'actual' => $eventName, 'message' => 'Push event should be dispatched');
         $testResults[] = array('expected' => true, 'actual' => $event->getProfile()->getDestination()->has('backup-application-test'), 'message' => 'Backup is pushed into destination');
     });
     $eventDispatcher->addListener(BackupEvents::TERMINATE, function (BackupEvent $event, $eventName) use(&$testResults) {
         $testResults[] = array('expected' => BackupEvents::TERMINATE, 'actual' => $eventName, 'message' => 'Terminate event should be dispatched');
     });
     $source = new GlobSource(realpath(__DIR__ . '/../Fixtures/glob/globSet1') . '/*');
     $processor = new ZipArchiveProcessor('archive.zip');
     $processor->setEventDispatcher($eventDispatcher);
     $namer = new Constant('backup-application-test');
     $rotator = new NullRotator();
     $destinationDirectory = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'roc_application_test';
     $filesystem = new Filesystem();
     $filesystem->remove($destinationDirectory);
     $destination = new LocalDestination($destinationDirectory);
     $profile = new Profile('my-profile', $source, $processor, $namer, $rotator, $destination, $rotator);
     $workflow = Workflow::build();
     $workflow->setEventDispatcher($eventDispatcher);
     $workflow->setLogger($logger);
     $manager = new Manager($workflow, array($profile));
     $manager->execute('my-profile');
     foreach ($testResults as $testResult) {
         $this->assertSame($testResult['expected'], $testResult['actual'], $testResult['message']);
     }
 }
Ejemplo n.º 3
0
 /**
  * @test
  *
  * @expectedException \RunOpenCode\Backup\Exception\ProcessorException
  */
 public function processException()
 {
     $logger = new NullLogger();
     $eventDispatcher = new EventDispatcher();
     $stub = $this->getMockBuilder('RunOpenCode\\Backup\\Processor\\NullProcessor')->getMock();
     $stub->method('process')->willThrowException(new ProcessorException());
     $processActivity = new Process();
     $profile = new Profile('test', new NullSource(), $stub, new Constant(), new NullRotator(), new NullDestination(), new NullRotator(), Workflow::build($eventDispatcher, $logger));
     $processActivity->setLogger($logger);
     $processActivity->setEventDispatcher($eventDispatcher);
     $processActivity->setProfile($profile);
     $processActivity->setBackup(new Backup('test'));
     $processActivity->execute();
 }
Ejemplo n.º 4
0
 /**
  * @test
  *
  * @expectedException \RunOpenCode\Backup\Exception\DestinationException
  */
 public function pushDestinationException()
 {
     $logger = new NullLogger();
     $eventDispatcher = new EventDispatcher();
     $destinationStub = $this->getMockBuilder('RunOpenCode\\Backup\\Destination\\NullDestination')->getMock();
     $destinationStub->method('push')->willThrowException(new DestinationException());
     $destinationStub->method('all')->willReturn(array());
     $pushActivity = new Push();
     $profile = new Profile('test', new NullSource(), new NullProcessor(), new Constant(), new NullRotator(), $destinationStub, new NullRotator(), Workflow::build($eventDispatcher, $logger));
     $pushActivity->setLogger($logger);
     $pushActivity->setEventDispatcher($eventDispatcher);
     $pushActivity->setProfile($profile);
     $pushActivity->setBackup(new Backup('test'));
     $pushActivity->execute();
 }
Ejemplo n.º 5
0
 /**
  * @test
  */
 public function nameSuccess()
 {
     $logger = new NullLogger();
     $eventDispatcher = new EventDispatcher();
     $nameActivity = new Name();
     $profile = new Profile('test', new NullSource(), new NullProcessor(), new Constant('new_name'), new NullRotator(), new NullDestination(), new NullRotator(), Workflow::build($eventDispatcher, $logger));
     $nameActivity->setLogger($logger);
     $nameActivity->setEventDispatcher($eventDispatcher);
     $nameActivity->setProfile($profile);
     $nameActivity->setBackup(new Backup('test'));
     $listener = function (BackupEvent $event) {
         $this->assertEquals('new_name', $event->getBackup()->getName(), 'Expected backup arrived with the event.');
     };
     \Closure::bind($listener, $this);
     $eventDispatcher->addListener(BackupEvents::NAME, $listener);
     $nameActivity->execute();
 }
Ejemplo n.º 6
0
 /**
  * @test
  */
 public function workflowErrorEvent()
 {
     $logger = new NullLogger();
     $eventDispatcher = new EventDispatcher();
     $sourceStub = $this->getMockBuilder('RunOpenCode\\Backup\\Source\\NullSource')->getMock();
     $sourceStub->method('fetch')->willThrowException(new SourceException());
     $profile = new Profile('test', $sourceStub, new NullProcessor(), new Constant(), new NullRotator(), new NullDestination(), new NullRotator());
     $errorTriggered = false;
     $eventDispatcher->addListener(BackupEvents::ERROR, function (BackupEvent $event, $eventName) use(&$errorTriggered) {
         $errorTriggered = true;
     });
     $workflow = Workflow::build();
     $workflow->setLogger($logger);
     $workflow->setEventDispatcher($eventDispatcher);
     try {
         $workflow->execute($profile);
     } catch (SourceException $e) {
         // noop
     }
     $this->assertTrue($errorTriggered);
 }