Stanislav Malyshev schrieb:
> This looks like factory pattern. What's wrong with implementing it as
> factory?

 Like I said before, the factory and singleton patterns are just example
 applications of this mechanism.

 What I want to use them for in PHPUnit is improving the Mock Objects
 system.

 Let us consider the following code:

   public function foo()
   {
       $bar    = new Bar;
       $returh = $bar->doSomething();

       // do something with $return

       return 'some value';
   }

 When I want to test the foo() method, I want to stub out the usage of
 the Bar class, for example, and have Bar::doSomething() return a
 pre-configured value instead of performing its normal operation.

 As I cannot pass a stubbed version of $bar into the method, I currently
 do not have a way to stub Bar.

 With class posing, however, I can override the "new Bar" and have it
 create an object of my stub implementation of Bar instead.

 I hope this makes my motivation for the feature more clear.

-- 
Sebastian Bergmann                          http://sebastian-bergmann.de/
GnuPG Key: 0xB85B5D69 / 27A7 2B14 09E4 98CD 6277 0E5B 6867 C514 B85B 5D69

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to