zend framework - Using let in phpspec -
i trying test class in phpspec. class regular service class used in zf2.
class guestservice implements servicelocatorawareinterface { public static function createwithservicemanager(servicelocatorinterface $servicelocator) { $guestservice = new guestservice(); $guestservice->setservicelocator($servicelocator); return $guestservice; } public function setservicelocator(servicelocatorinterface $servicelocator) { $this->services = $servicelocator; } }
my spec is:
class guestservicespec extends objectbehavior { function let(servicelocatorinterface $servicemanager) { $this->beconstructedthrough('createwithservicemanager' , [$servicemanager]); } }
i'm having troubles understanding how phpspec create servicemanager object in first place call constructed through function. in zend have factory closure allows construction similar static method given above.
i have seen example of object construction on phpspec manual uses writer object pass constructor. not explain how writer object created.
i can see similar examples on page have objects passed phpspec functions.
function it_does_something_if_argument_is_false(writer $writer) { $this->beconstructedwith($writer, false); // constructed second argument set false // ... }
but not explain how writer object constructed. how servicemanager constructed?
in case $writer
, $servicemanager
stubs. phpspec parses type hints in methods (writer
, servicelocatorinterface
) , creates stubs using reflection. there copies of original classes copied methods, without implementation.
you can read more here
Comments
Post a Comment