Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The easiest way to do basic Unit testing in BMO is to test the entire thing.

Code Block
languagephp
public static $dbDefaults = array ( "bestpony" => "Rainbow Dash" );
 
public function doTests($db) {
    $_REQUEST['bestpony'] = "Twilight Sparkle";
    $_REQUEST['display'] = "extensions";
    $_REQUEST['Submit'] = "submit";
    if ($this->getConfig("bestpony") != "Rainbow Dash") {
        throw new Exception("BMO Didn't load the default for Best Pony");
    }
    $this->doConfigPageInit($_REQUEST['display']);
    // Now, assuming your configPageInit captured 'bestpony' and set its config var to that..
    if ($this->getConfig("bestpony") != "Twilight Sparkle") {
        throw new Exception("My doConfigPageInit didn't capture bestpony");
    }
    return true;
}

...

When you discover a bug, write a test that finds that bug:

Code Block
languagephp
public function addOne($var) {
    // Add one to $var
    return $var + 2;
}
 
public function doTests() {
    if ($this->addOne(1) != 2) {
        throw new Exception("1 + 1 didn't equal 2");
    }
    return true;
}

...