php - Stub for formal parameter passed by reference in PHPSpec/Prophecy -
i have method in php looks this:
<?php class someclass { public function isentitledtodiscount(guestmodel $who, $onwhat, &$discountamount = null) { $discountamount = 10; return true; } }
is there way stub $discountamount
in phpspec? let's have class i'm testing, , i've injected $someservice
via constructor. in spec use:
<?php $someservice->isentitledtodiscount($guest, $ticket, $discountamount)->willreturn(true);
which creates stub method return value. how can $discountamount
formal parameter?
a method shouldn't modify arguments (shouldn't have side effects). getter-type method. you should rethink design.
your problem related prohpecy, might want read docs: https://github.com/phpspec/prophecy
prophecy (and phpspac) make things hard. in cases means you're trying take wrong turn design.
you try following, don't think you'll reference variable:
$someservice->isentitledtodiscount($guest, $ticket, $discountamount) ->will(function ($arguments) { // evil });
recommended read: command query separation.
Comments
Post a Comment