php - How to test the order of parameters passed to an object constructed by a method -
i'm testing simple factory class single method returns 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'] ); } }
i can test method…
public function testbuildfromarray() { $tagdata = [ 't_id' => 1, 't_promotion_id' => 2, 't_type_id' => 3, 't_value' => 'you valued', ]; $tagfactory = new tagfactory(); $result = $tagfactory->buildfromarray($tagdata); $this->assertinstanceof(tagmodel::class, $result); }
if change order of parameters in new tagmodel…
test still pass.
if prophesize tagmodel
…
$tagmodel = $this->prophesize(tagmodel::class); $tagmodel->willbeconstructedwith( [ $tagdata['t_id'], $tagdata['t_promotion_id'], $tagdata['t_type_id'], $tagdata['t_value'] ] );
… should asserting? assertsame
doesn't work because aren't.
i test order getters tagmodel
i've gone beyond testing unit. yet feel order should tested because if change them test still passes.
the method you're testing factory. creates object. if making sure it's of expected type not enough you, need verify state. either inspect getters, or create object you're expecting receive , use assertequals() compare it.
Comments
Post a Comment