我开始使用 phpunit,而且我对 OO PHP 的接触有限,所以我认为我缺少一些基本的东西。在设置一个非常简单的测试时,我得到了错误Trying to get property of non-object
。
这就是我要测试的
class Employee
{
protected $jobTypeModifier, $manager, $id;
public $name, $employee, $years, $allowances, $allowances_left, $extra, $carried, $totalTaken, $holidays;
function Employee($id)
{
$this->jobTypeModifier = 1;
$this->manager = 0;
$this->totalTaken = 0;
$this->setEmployeeId($id);
}
function myId()
{
return $this->id;
}
}
这是我的测试
class EmployeeTest extends PHPUnit_Framework_TestCase
{
protected $employee;
protected function setUp(){
$this->employee = new Employee(1);
}
protected function tearDown() {
unset($this->employee);
}
public function testMyId()
{
$actual = $this->employee->myId();
$expected = 1;
$this->assertEquals($actual, $expected);
}
}
我想我在这里遗漏了一些基本/明显的东西?