Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:32559 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 98314 invoked by uid 1010); 2 Oct 2007 17:10:34 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 98299 invoked from network); 2 Oct 2007 17:10:34 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Oct 2007 17:10:34 -0000 Authentication-Results: pb1.pair.com smtp.mail=sb@sebastian-bergmann.de; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=sb@sebastian-bergmann.de; sender-id=unknown Received-SPF: error (pb1.pair.com: domain sebastian-bergmann.de from 62.4.74.185 cause and error) X-PHP-List-Original-Sender: sb@sebastian-bergmann.de X-Host-Fingerprint: 62.4.74.185 mail-2.de-punkt.de Received: from [62.4.74.185] ([62.4.74.185:47392] helo=mail-2.de-punkt.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 3E/96-57391-88B72074 for ; Tue, 02 Oct 2007 13:10:33 -0400 Received: (qmail 22398 invoked by uid 511); 2 Oct 2007 17:10:25 -0000 Received: by simscan 1.3.1 ppid: 22389, pid: 22395, t: 0.0557s scanners: attach: 1.3.1 clamav: 0.90.2/m:/d:3966 Received: from unknown (HELO ?192.168.2.31?) (sb%sebastian-bergmann.de@80.136.223.150) by 0 with ESMTPA; 2 Oct 2007 17:10:24 -0000 Message-ID: <47027B78.5070909@sebastian-bergmann.de> Date: Tue, 02 Oct 2007 19:10:16 +0200 Reply-To: internals@lists.php.net User-Agent: Thunderbird 2.0.0.6 (Windows/20070728) MIME-Version: 1.0 To: internals@lists.php.net References: <4702777C.2090406@zend.com> In-Reply-To: <4702777C.2090406@zend.com> X-Enigmail-Version: 0.95.2 OpenPGP: id=B85B5D69; url=http://sebastian-bergmann.de/gpg-key.asc Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Class Posing From: sb@sebastian-bergmann.de (Sebastian Bergmann) 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