Here's my idea: addAction() buffers actions; each action is a separate small class. The commit method performs the actual actions, in order, and throws an exception if there is failure. The exception thrown can to be passed a rollback() method.
Several try catch blocks wrapped in one overall large try catch can be used to continue despite failure selectively:
Code: Select all
$inst = new FsTrans();
try {
$inst->addAction('NewDir', array('foo'));
try {
$inst->addAction('SetPermissions', array('foo', 0777));
$inst->commit();
} catch (FsTrans_Exception $e) {
echo "Failed to set directory permissions on foo\n";
// continuing...
}
$inst->addAction('ChangeDir', array('foo'));
$inst->addAction('NewFile', array('bar.txt', 'bar'));
$inst->commit();
} catch (FsTrans_Exception $e) {
$inst->rollback();
}How do you suggest I unit test this? Am I going to have to setUp() certain file/directory structures to run this in and tearDown() them after. I've written things like that before and they get pretty damn confusing. Finally, how could I make code that uses this testable?