Improving CTestCase for model classes

Hi,

I’ve revealed that CTestCase is required special group of assert methods like as:




class TestCase extends CTestCase {

  public function getNotPulicMethod($classname, $methodName) {

    $class = new ReflectionClass($classname);

    $method = $class->getMethod($methodName);

    $method->setAccessible(true);

    return $method;

  }

  protected function assertSaveModel(CModel $model, $message = '') {

    $this->assertTrue($model->save(),

                      "Saving model; $message:\n"

                      . CVarDumper::dumpAsString($model->errors));

  }

  protected function assertValidateModel(CModel $model, $message = '') {

    $this->assertTrue($model->validate(),

                      "Validating model; $message:\n"

                      . CVarDumper::dumpAsString($model->errors));

  }

  protected function assertDeleteModel(CModel $model, $message = '') {

    $this->assertTrue($model->delete(),

                      "Deleting model; $message:\n"

                      . CVarDumper::dumpAsString($model->errors));

  }

  protected static function prepare($message) {

    if (is_array($message) or is_object($message))

      return CVarDumper::dumpAsString($message);

    return $message;    

  }

  public static function assertEquals($expected, $actual, $message = '') {

    parent::assertEquals($expected, $actual, self::prepare($message));

  }

  public static function assertTrue($condition, $message = '') {

    parent::assertTrue($condition, self::prepare($message));

  }

}




They really save many time.

Thanks.