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

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -