我正在尝试为返回false或object的函数编写测试。
class Environment {
protected $db , $env, $envMapper= "";
public function __construct($dbConnection) {
$this->db = $dbConnection;
$this->setMapper($this->db);
}
public function setMapper($db){
$this->envMapper=new DB\SQL\Mapper($this->db,'environment');
}
public function save($envName) {
$this->envMapper->name = $envName;
return $this->envMapper->save();
}
/**
* @param $envId
*/
public function get($envId) {
}
/***
* @param $envName
*/
public function getByName($envName) {
}
}
试验:
class EnvironmentTest extends PHPUnit_Framework_TestCase {
protected $db = "";
public function setup()
{
$this->db = $this->getMockBuilder('SqlHelper')
->setMethods(array('connect'))
->getMock();
}
public function testSave() {
$object = new StdClass();
$env = new Environment($this->db);
$this->assertEquals($object, $env->save('Test'));
}
}
我不知道应该如何更改,以便它可以测试,它总是返回
EnvironmentTest :: testSave PHPUnit_Framework_MockObject_RuntimeException:您无法序列化或 反序列化PDO实例