/**
  * Runs the specified job and returns job statistics
  *
  * @param BackupJob $job
  * @param OutputInterface $output
  * @author Daniel Wendlandt
  * @return JobStats
  */
 public function execute(BackupJob $job, OutputInterface $output)
 {
     $memoryAtStart = memory_get_usage();
     $timeStart = microtime(true);
     $jobStats = new JobStats();
     //SECTION create_structure
     $this->createStructure($job, $jobStats, $output);
     //SECTION store_mappings
     $this->storeMappings($job, $jobStats, $output);
     //SECTION store_data
     $storedStats = $this->storeData($job, $jobStats, $output);
     //Section store_meta_data
     $this->storeMetaData($job, $jobStats, $storedStats, $output);
     //global stuff
     $this->filesystem->symlinkLatestBackup($job->getPath());
     $output->writeln('<info>*** Symlinked ' . $job->getPath() . ' to latest ***</info>' . PHP_EOL);
     //store backup as config in config folder
     $this->storeBackupConfig($job, $output);
     //handle jobs stats and tore it to filesystem
     $jobStats->setTimeTaken(microtime(true) - $timeStart);
     $jobStats->setMemoryUsed(memory_get_usage() - $memoryAtStart);
     $jobStats->setMemoryUsage(memory_get_usage());
     $jobStats->setMemoryUsageReal(memory_get_usage(true));
     $this->storeJobStats($job, $jobStats, $output);
     $output->writeln('');
     $output->writeln($this->getResultLineForOutput($jobStats));
     return $jobStats;
 }
 public function testSymlinkLatestBackupExisting()
 {
     $path = '/tmp/test-path';
     $latestPath = dirname($path) . DIRECTORY_SEPARATOR . FilesystemRepositoryInterface::SYMLINK_LATEST;
     $this->filesystem->expects($this->once())->method('exists')->with($latestPath)->willReturn(true);
     $this->filesystem->expects($this->once())->method('remove')->with($latestPath);
     $this->filesystem->expects($this->once())->method('symlink')->with($path, $latestPath);
     $this->filesystemRepository->symlinkLatestBackup($path);
 }