This may just be a configuration thing with PhpUnit (I’m relatively new using it), but I’m having testing fail because the getBaseURL() isn’t returning a correct URL within a test.
For example, I have a class and function:
public static function GetImagePath($strFile) {
return Yii::app()->getBaseUrl() . "/images/" . $strFile;
}
class ImageTest extends CDbTestCase
{
public function testGetImagePath() {
$strName = Images::GetImagePath('test1.jpg');
$this->assertEquals("www.example.com/images/test1.jpg",$strName);
}
}
This will fail because the URL being generated is:
I have the same problem with this and other Yii::app() -calls. Since I am new in testing with PHPUnit I am also looking for an answer. I’ll write what I found till now - correct if I am wrong
Yii::app() -calls are static (. They bring data from outside the method - and you can’t trust on which data is delivered. While testing a method you don’t want to have such disturbance and so you mock (or stub ?) this external calls.