Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:100233 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 70159 invoked from network); 16 Aug 2017 20:21:16 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Aug 2017 20:21:16 -0000 Authentication-Results: pb1.pair.com smtp.mail=cmbecker69@gmx.de; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=cmbecker69@gmx.de; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmx.de designates 212.227.15.15 as permitted sender) X-PHP-List-Original-Sender: cmbecker69@gmx.de X-Host-Fingerprint: 212.227.15.15 mout.gmx.net Received: from [212.227.15.15] ([212.227.15.15:56067] helo=mout.gmx.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F0/87-34801-B39A4995 for ; Wed, 16 Aug 2017 16:21:16 -0400 Received: from [192.168.2.123] ([79.243.116.167]) by mail.gmx.com (mrgmx002 [212.227.17.190]) with ESMTPSA (Nemesis) id 0M7Hao-1dLU373WpK-00x0az; Wed, 16 Aug 2017 22:21:12 +0200 To: Ryan Jentzsch , Internals References: Message-ID: <36045e9c-876f-3bc6-b296-3a99dc8afdf0@gmx.de> Date: Wed, 16 Aug 2017 22:21:16 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: de-DE Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:Pd8YB+J6RIZeo1aYZZdPl0xGFE1ad9bwj1BC2zqeFA03w0Ki4p7 93lwc1EGoH3xABOLRnkMC3Z2OHpYKveGnCxo36ilDAU0ITu5mNp6JAS10sm9j0//XUB1gIe StVO4lmkQSSUo6OqC1NtvSq1wtjSTVJ3bZIhMvIrCXxzl4A1PxIEQNe7RvpKZ8LaDfpUNov /DNA00HRiZyl0QljElOAQ== X-UI-Out-Filterresults: notjunk:1;V01:K0:XO5ji3Flw2U=:v5EvyWtul8IBl2ojV+cR9d BZfvBGJAo9JvzwdYurVPaWxYlKaYeeGe8yEOY9pVTkWWUZSeKsWL3tdWk+aFE/UFW98K/Vmrf BTjnvGyKCnugIonz2mpovq/q8jrtLp8CBzQoUaQsdoQj86azR1nb16hIwbTWPn+b1FfbsKaMt BgexUlvKH3qmw73jbKn7AuCHIDWPUWBXW1Qy1Q1vsLFylqzhqQ5xZFvID6bN6ERQL27tH8OH9 y60wr+PljyLn+SMyUd6+BcQiueRKRbwydVWL68V49QUelXAeYtbWA8lEYPfXFTG7UfYyz8CpR vvbzldnayMSO1gWmGPVTFRvvhqtUXoq+UlELrhktoVOhrR09/CYXuRb60jlObGiVvtn1Y9TCI lk/kxtlaT1oa8+ny+kDmMvUVAOi5OQwTIpBf3dKFw8QiZAOSbcB1L2pOcWXvozHWk9CBQIls4 Ln2UMDuZeNGR8nHR9g2l/1jG8b7/EKE1oIhJsN8hVB2PnR7gV1XE6x+0OO2bLQnqrcMHfBYJt wlOKFp70CITJQ2gYt8seDTwSoaxHP/5KgbVAr9/qW1MoHB+WMyFH0Txhqiwi03c9FyuN9ZtIO 2MD0bID+1soyoXQQOI452G3tq0erVNRT/DE8tSbXyDVdNHwalTbPV2iiQc44jIw+zrlcI/3Bh 18Foc/N1yAvSH2gc6XehM7EsSJFk8g1nFVqaA4IZeVTgKixOZVNj/os03U8MtEKnTnIpDIa6j kZK01Ygdv4+735tkCj88wouRKtMZuNNj/OqZNxYEmXJWvqdejKTaWYtu1CnoNZbol8X1lfnO9 0hUh8h5MPmkMvzshKirpsOv0+DE6+YdesG2ENSFvm17t3fINQI= Subject: Re: Easy method of overriding built-in php functions. From: cmbecker69@gmx.de ("Christoph M. Becker") On 16.08.2017 at 22:02, Ryan Jentzsch wrote: > I am aware of Advanced PHP debugger but what I need this type of > functionality for is mocking and testing. > > As an example I want to use PHPUnit mocking feature to create a mock of a > class. However in the constructor of this class is the following line to > get the expected JSON string: > > $result = file_get_contents('php://input'); > > I can not override the file_get_contents() function. The work around is to > monkey patch the class as a mock and override the constructor (copying ALL > logic from the constructor to the mock allowing for $result to be taken > from the constructor's argument list). > > This is awkward and in my use case the constructor also makes calls to > static methods in other objects which the latest version of PHPUnit does > not allow you to mock static methods. > > ADP is not acceptable to override functions in that it requires a binary to > be installed and php.ini to be configured as well as no support for this in > Windows. > > Is there an RFC that I didn't find that allows for easily overriding > built-in functions? For example: > > @function file_get_contents($string) > { > return 'mock string'; > } > > My C skills are quite rusty and understanding the Zend engine is a daunting > task or I'd create an RFC myself. The devil is in the details. The real > question I am asking is HOW DIFFICULT would something like this be to code > and include in the PHP core? There are already runkit and uopz which allow to override existing functions: * * -- Christoph M. Becker