public function create(array $data)
{
try {
$house = $this->createHouseFromType($data[self::KEY_TYPE]);
$house->setValue($data[self::KEY_VALUE]);
$house->setNewBuild($data[self::KEY_NEW_BUILD] == self::NEW_BUILD_INDICATOR);
$house->setHitPoints($this->hitPointCalculator->calculate($house));
return $house;
} catch(RejectedProperty $exception) {
return false;
}
}
private function createHouseFromType($type)
{
switch($type) {
case self::DETACHED_INDICATOR:
return new \DeadStreet\ValueObject\House\Detached();
case self::SEMI_DETACHED_INDICATOR:
return new \DeadStreet\ValueObject\House\SemiDetached();
case self::TERRACE_INDICATOR:
return new \DeadStreet\ValueObject\House\Terrace();
default:
throw new RejectedProperty();
}
}
测试本身
public function test_throwsRejectedPropertyExceptionIfCannotAllocateType()
{
$data = [
0 => null,
1 => 100000,
2 => null,
3 => 'HU13 9LL',
4 => null,
5 => 'Y'
];
$this->createObject()->create($data);
$this->expectException(RejectedProperty::class);
}
我无法理解为什么会失败,它正在运行
default:
throw new RejectedProperty();
错误
1) DataAccess\CSV\House\Factory_Test::test_throwsRejectedPropertyExceptionIfCannotAllocateType
声明类型" DataAccess \ CSV \ House \ RejectedProperty"的异常失败扔了。