我正在使用第三方库(因此无法更改静态方法调用的使用),即 ORM。现在为了让它工作,我的“实体”类必须扩展他们的实体类,它使用静态方法继承了几个依赖项,我想测试我的实体类抽象出这些静态调用,但不确定如何
代码如下:
// Entity class ripped from third party library
class Entity
{
// other methods etc
/**
* Setter for field properties
*/
public function __set($field, $value)
{
$fields = $this->fields();
if(isset($fields[$field])) {
// Ensure value is set with type handler
$typeHandler = Config::typeHandler($fields[$field]['type']);
$value = $typeHandler::set($this, $value);
}
$this->_dataModified[$field] = $value;
}
}
// my Entity class
class User extends Entity
{
public static function fields()
{
return array(
'id' => array('type' => 'int', 'primary' => true, 'serial' => true),
'fullname' => array('type' => 'string', 'required' => false),
'email_address' => array('type' => 'string', 'required' => true, 'email' => true),
);
}
}
$user = new User();
$user->fullname = 'John Doe'; // dependancy on Config::typeHandler
现在我想模拟允许我设置变量的 Config 对象,我该怎么做?
谢谢