1
我測試簡單工廠類與它返回一個TagModel
單個方法構造的對象參數的順序。如何測試的傳遞給通過一種方法
class TagFactory
{
public function buildFromArray(array $tagData)
{
return new TagModel(
$tagData['t_id'],
$tagData['t_promotion_id'],
$tagData['t_type_id'],
$tagData['t_value']
);
}
}
我可以測試方法...
public function testbuildFromArray()
{
$tagData = [
't_id' => 1,
't_promotion_id' => 2,
't_type_id' => 3,
't_value' => 'You are valued',
];
$tagFactory = new TagFactory();
$result = $tagFactory->buildFromArray($tagData);
$this->assertInstanceOf(TagModel::class, $result);
}
如果我更改了new TagModel…
參數的順序測試仍然會通過。
如果我prophesize的TagModel
...
$tagModel = $this->prophesize(TagModel::class);
$tagModel->willBeConstructedWith(
[
$tagData['t_id'],
$tagData['t_promotion_id'],
$tagData['t_type_id'],
$tagData['t_value']
]
);
...但我應該怎麼那麼可以斷言? assertSame
不起作用,因爲它們不是。
我可以測試從TagModel
的干將順序,但那時我已經超越了測試只是這個單位。但我確實認爲應該測試訂單,因爲如果我改變它們,測試仍然通過。
謝謝,我已經做了,這意味着這個測試基本上成爲TagModel測試以及測試的參數是正確的順序通過。 – deadlyhifi