Right now the testing tools are very basic, we need a better way to test the module.

Instructions to create a mockup file set:

  1. Navigate to your destination folder (eg. manual backup directory).
  2. Run the createMockupFiles.php script with a CLI interpreter. In a shell type: php -f /path/to/createMockupFiles.php. NOTE: You may want to tune the number of backups and the time between backups.
  3. Manually prune your backups & inspect the results.

The code for createMockupFiles.php:

$datetime = new \DateTime('now', new \DateTimeZone('Europe/Berlin'));
for ($i=0; $i < 5000; $i++) {
  $template = '';
  $timestamp = $datetime->getTimestamp();
  $filename = "BackupMigratePrunedemo-" . $datetime->format("Y-m-d\TH-i-s");

  $template .= 'filename = ' . $filename;
  $template .= "\n" . 'description = ""';
  $template .= "\n" . 'datestamp = "' . $timestamp . '"';
  $template .= "\n" . 'generator = "Backup and Migrate (http://drupal.org/project/backup_migrate)"';
  $template .= "\n" . 'generatorversion = "7.x-2.x"';
  $template .= "\n" . 'sites[0][version] = "7.18"';
  $template .= "\n" . 'sites[0][name] = "Backup Migrate Prune demo"';
  $template .= "\n" . 'sites[0][url] = "http://bmp.local:8888/"';

  $backup_name = $filename . '.mysql.gz';
  $info_name = $backup_name . '.info';
  touch($backup_name, $timestamp, $timestamp);
  file_put_contents($info_name, $template);
  touch($info_name, $timestamp, $timestamp);
  echo "$i. Created mockup for $filename\n";
  $interval = new \DateInterval('PT6H30M12S');
  $interval->invert = 1;
  $datetime->add($interval);
}

Very important note

I cannot seem to be able to fake a timestamp that is read by filectime so to test the mockup file set you will need to temporarily hack Backup and Migrate.

Go to includes > files.inc in the B&M module and change filectime for filemtime on the set_filepath method. Remember to edit your changes back once your tests are finished.

Comments

salvis’s picture

I wonder -- would it be possible to implement a

class backup_migrate_destination_prunetest extends backup_migrate_destination

that mocks the entire destination?

I know almost nothing about how B&M is implemented, but I would expect that you could replace the file system in the backup_migrate_destination_files class with an array of mocked file descriptors in your mock destination "file system".

One of the filectime() calls in files.inc seems to be related to temporary files, which are likely to always be files. Maybe I'm missing something, but it seems that the set_filepath() method should not be called if our destination is not a file system that can do filectime().

e0ipso’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev
Status: Active » Fixed

Release 7.x-2.x now has unit testing for the most common scenario. I implemented the tests as salvis proposed.

Bugs with tests and follow ups in new issues.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Corrected filename