我是测试的新手。我正在使用PHPUnit Framework。我读到了关于静态函数的嘲弄和存根,但即使这些概念对我来说也是新的。我想对以下功能进行单元测试
class Company implements ifOrm {
public $id = null;
public $externalId = null;
public $name = null;
public $created = null;
public $modified = null;
public $state = null;
private $arrService = array();
public function __construct($externalId, $name, $state) {
$this->externalId = $externalId;
$this->name = $name;
$this->state = $state;
}
public static function factoryFromObject($obj) {
$c = new Company($obj->external_id, $obj->name, $obj->state);
// Tag it
$c->id = $obj->id;
$c->created = $obj->created;
$c->modified = $obj->modified;
return $c;
}
}
到目前为止我所做的是以下
class CompanyTest extends PHPUnit_Framework_TestCase
{
private $Company;
public function testFactoryFromObject()
{
$this->Company = new Company( 004 ,'CompanyName','State');
$returnObject = $this->Company->factoryFromObject($this->Company);
$expectedId = $this->Company->id;
$expectedCreated = $this->Company->created;
$expectedModified = $this->Company->modified;
$actualId = $this->returnObject->id;
$actualCreated = $this->returnObject->created;
$actualModified = $this->returnObject->modified;
assertEquals($expectedId, $actualId);
assertEquals($expectedCreated, $actualCreated);
assertEquals($expectedModified, $actualModified);
}
}
我收到以下错误:
Undefined property: Company::$external_id
我如何测试这个功能,任何帮助都会很棒,谢谢。