$m = new sfClassManipulator($source); $t->is($m->wrapMethod('foo', '// code before'), $sourceWithCodeBefore, '->wrapMethod() adds code before the beginning of a method.'); $m = new sfClassManipulator($source); $t->is($m->wrapMethod('foo', '', '// code after'), $sourceWithCodeAfter, '->wrapMethod() adds code after the end of a method.'); $t->is($m->wrapMethod('foo', '// code before'), $sourceWithCodeBeforeAndAfter, '->wrapMethod() adds code to the previously manipulated code.'); // ->getCode() $t->diag('->getCode()'); $m = new sfClassManipulator($source); $t->is($m->getCode(), $source, '->getCode() returns the source code when no manipulations has been done'); $m->wrapMethod('foo', '', '// code after'); $t->is($m->getCode(), $sourceWithCodeAfter, '->getCode() returns the modified code'); // ->setFile() ->getFile() $t->diag('->setFile() ->getFile()'); $m = new sfClassManipulator($source); $m->setFile('foo'); $t->is($m->getFile(), 'foo', '->setFile() sets the name of the file associated with the source code'); // ::fromFile() $t->diag('::fromFile()'); $file = sys_get_temp_dir() . '/sf_tmp.php'; file_put_contents($file, $source); $m = sfClassManipulator::fromFile($file); $t->is($m->getFile(), $file, '::fromFile() sets the file internally'); // ->save() $t->diag('->save()'); $m = sfClassManipulator::fromFile($file); $m->wrapMethod('foo', '', '// code after'); $m->save(); $t->is(file_get_contents($file), $sourceWithCodeAfter, '->save() saves the modified code if a file is associated with the instance'); unlink($file); // ->filterMethod() $t->diag('->filterMethod()');