Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:100231 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 67087 invoked from network); 16 Aug 2017 20:02:34 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Aug 2017 20:02:34 -0000 Authentication-Results: pb1.pair.com header.from=ryan.jentzsch@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ryan.jentzsch@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.161.182 as permitted sender) X-PHP-List-Original-Sender: ryan.jentzsch@gmail.com X-Host-Fingerprint: 209.85.161.182 mail-yw0-f182.google.com Received: from [209.85.161.182] ([209.85.161.182:33000] helo=mail-yw0-f182.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 4A/D6-34801-AD4A4995 for ; Wed, 16 Aug 2017 16:02:34 -0400 Received: by mail-yw0-f182.google.com with SMTP id p68so29359253ywg.0 for ; Wed, 16 Aug 2017 13:02:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=F01sNcFlZi6WERADww6+v7ayoe0swue/dm4MhYsLRaQ=; b=vZ2RJC3nN8YUYK5S6nseVjoQWRFiEAKCmIOq397Tfj6NsSP4eMBOoZO69h9OA+aT2D DOQ9kElNs+7v3y6R30JqKxO1bNNtz4L7h+spIznmnvs+VkN+lgxi6pr2Q3/gVctINkEg g3LcjmQmXBcmjs3fJetbarBq3i2DahWtjJtSVq0FqAmFm0nrPWx8I3GPyBsWO2fQko4s EwGQ5bRcAplBwgqcJniTEw79L/UuybEH1+GLbglK59tkOMwOMx6gG0OpDdKYkJxMsvss J4GtUuMqZ2z3khG8hZiaCItdS2eCtY/1Mt90oVFYNsddKNK4NKAw8kHYgNyndLu8Pa2J IbNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=F01sNcFlZi6WERADww6+v7ayoe0swue/dm4MhYsLRaQ=; b=nP07q0uhSHWtM4rYrjRC9GdwAoUeBH6+xHFizygIuNKCqG7rfpOp9VdtIaf/nkWFFD +MK5ypKzIuMkHuVCKK68ORcT0tOHflCCblqAKCadHJ6wfdd8jsJmdSIxN1SDVltnobZY 36D4SgJF4mNX77CYNLMYv6JkACoVq44TUTLkli7mMHmPEMR9mfkIkh14KhA3/h57Op3n 8rYnrZoM+9SjmMbexxpeKcSpckANG8plSzSDvqf17/rNnDt6W0ouooUjb141Lh27dwj0 1V3IjdRg5HPwzbU2QvD0vKooC2amBc9Axasb85kBOqhNoF9ydr/tVhnIF+z/xyumNvRU MMNg== X-Gm-Message-State: AHYfb5hHlxiaf1LMr2LsZyQKGblbiImYB5vjhCUDbonlDwplvzUZrJNS 3hJZTmio4ObrDsQ3CkxPYjAz+Ul6M2gW X-Received: by 10.37.173.28 with SMTP id y28mr2332462ybi.78.1502913751814; Wed, 16 Aug 2017 13:02:31 -0700 (PDT) MIME-Version: 1.0 Received: by 10.129.2.2 with HTTP; Wed, 16 Aug 2017 13:02:01 -0700 (PDT) Date: Wed, 16 Aug 2017 14:02:01 -0600 Message-ID: To: Internals Content-Type: multipart/alternative; boundary="f403045da1824e2b7f0556e460f3" Subject: Easy method of overriding built-in php functions. From: ryan.jentzsch@gmail.com (Ryan Jentzsch) --f403045da1824e2b7f0556e460f3 Content-Type: text/plain; charset="UTF-8" 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? --f403045da1824e2b7f0556e460f3--