Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:124797 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id D2B621A00B7 for ; Tue, 6 Aug 2024 08:57:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1722934768; bh=qK1FIXHKeaW6cTU3aYKjtPJ9fn9Vxbcz5nRC7Z/n7Lo=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=dZenCh+lliUFZGl0bKh1qjnM/2+vmZRO/JitXtpaMuT+guFyuKfM3QHSQ6emABNBm hhM34d90PGJbVDAsQ1gugXUwVWUBKJTh53lKfCo8W6FIoxrBCpi8mw+BGyGaeoolMk DCP/6GLp9TR3v/NLD/zWptxy71VVCUR9N5w8+qK4b3cPmbrOznSIdZ7EJFK3Hc2wVg MzchORmXxFeIlYW8qWTyytgmAk00og/UoDCxoRxGeRTkLWgJ8kT6tfFMruaLMj7ej/ pCZADv5LPBqF2y5lJadjCe131vV2qKKGbVYdz520x7iG5G2B+kCMO9n0htHx+seK1i 99gPt0E13TbXQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 3C3891801E7 for ; Tue, 6 Aug 2024 08:59:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DMARC_MISSING,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-yw1-f178.google.com (mail-yw1-f178.google.com [209.85.128.178]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 6 Aug 2024 08:59:22 +0000 (UTC) Received: by mail-yw1-f178.google.com with SMTP id 00721157ae682-66acac24443so2969117b3.1 for ; Tue, 06 Aug 2024 01:57:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20230601.gappssmtp.com; s=20230601; t=1722934661; x=1723539461; darn=lists.php.net; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=qK1FIXHKeaW6cTU3aYKjtPJ9fn9Vxbcz5nRC7Z/n7Lo=; b=TY8X0kw9c4XwsNsIwa1kcjOL0XvuJglAqwY/I92E+qiBuMC6WRs0+ow1VrAsvQeGxs PTapZrQHX/9g8qRb//wJB/Hv3q2sYT0EVL3lEIxsHoKS3mdL7SZJgK2R3WuhuUP9vRlz E9hqN22sVeGsWX13KRh327o+HA3zxiPlACxVrnJ2PtodEulAJz93Eiby1SguuMSKYSEo lnfrOVTJ4ZYhWvORTEpU/GnqgE8Br2YQKYRZgXO70DYflY9Bwmpk0meWqS6Tr7CZqrdp bb8dGmT7zf6baHBSbe34xUDKcxqAd+hCmIOy5bs7GGYl8WP+jiS4TszeqdPXP7AEkwlA xH7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722934661; x=1723539461; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qK1FIXHKeaW6cTU3aYKjtPJ9fn9Vxbcz5nRC7Z/n7Lo=; b=XswSEoqEFj65DFkY/vGYMA/xBjHkDqn0a4wHFbnhwyUJqkX09grDsZt0h1RApwaXeY +TOrN2KQqQxeOFxnCMe9r2/4z6gfI5Men651vir8RDPtSwsDqfQBIkC6vxtoVh/zSjGX Jih1TmaV9J0qoqAprl2W0XjYRqtmaoSABWOYrsVmC8D6//Z0qgH25Mix3WQpMp+VBWbh 7vkH9gZ2RjpaDHTHRJP7zLo+Q6Qip4xJYWj8KyVjiYKa7aFdiEeQlvMixHNqI2Ce0T2B zw8a7ip4n65Z2oQEG/wKgD+gXeaokZai3QTJFiMHcXcFIes2igeEolt+poQAn4Y8zhEm WCrg== X-Gm-Message-State: AOJu0Yx1yoP+ZVEaLbLz4pVmcmLDZAm9vXyZHaOcO/rwU8cbe1eobaQ3 Xh+NHH2DNtL6MPW2mByZGM4iSUeuYt8OS233l9tKjYgljLtGMAqok47/XHVjJUUYCzossF2oZJP J78E= X-Google-Smtp-Source: AGHT+IHnaHuQIiHXu0pX9XsJ+tJ+CawD11MIAMMK/qitWi0As3wyCvjM1ktGrbcOUAIYCtgCmBv6Ww== X-Received: by 2002:a81:8746:0:b0:650:8f3a:2ac6 with SMTP id 00721157ae682-6895f9edb50mr144079097b3.1.1722934660727; Tue, 06 Aug 2024 01:57:40 -0700 (PDT) Received: from smtpclient.apple (c-98-252-216-111.hsd1.ga.comcast.net. [98.252.216.111]) by smtp.gmail.com with ESMTPSA id 00721157ae682-68a140613bcsm14874477b3.135.2024.08.06.01.57.40 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Aug 2024 01:57:40 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.8\)) Subject: Re: [PHP-DEV] [Discussion] Sandbox API In-Reply-To: Date: Tue, 6 Aug 2024 04:57:39 -0400 Cc: PHP internals Content-Transfer-Encoding: quoted-printable Message-ID: <95EDE362-6618-401F-8CD9-2D7C2F05B205@newclarity.net> References: To: Nick Lockheart X-Mailer: Apple Mail (2.3696.120.41.1.8) From: mike@newclarity.net (Mike Schinkel) > On Aug 6, 2024, at 2:09 AM, Nick Lockheart = wrote: >=20 > Sand Box: A first class API that allows unit testing of code with = mocks > and stubs of other classes or functions, without the need to modify = the > class under test. >=20 > This is an initial idea of how a Sand Box API could work: >=20 > $oSandbox =3D new SPLSandBox(); >=20 > $oSandbox->MockFunction('\mocks\fopen','\fopen'); > $oSandbox->MockFunction('\mocks\fread','\fread'); > $oSandbox->MockFunction('\mocks\fwrite','\fwrite'); > $oSandbox->MockFunction('\mocks\fclose','\fclose'); >=20 > $oFileManager =3D $oSandbox->GetInstance('MyFileManager'); >=20 > $oFileManager->WriteFile('/path/to/file.txt'); On the surface, this sounds like a good idea. This is already possible to do in userland, with a few edge-cases. The = edge-cases are: 1. Anything that uses `self::class` or similar will break if it expects = `MyFileManager` to be returned instead of something like = `MyFileManager_4k2x8j`. 2. Anything that expects a static variable in `MyFileManager` to have a = pre-existing value set but an earlier use of `MyFileManager` will not = work as expected. However, expecting that would be against testing best = practices so I don't see this as a real concern given your use-case. OTOH, a userland implementation will also not be very performant when = compared to a potential PHP core implementation, making it less than = ideal for testing.=20 However, doing a userland implementation would be a good = proof-of-concept, allow others to try it, allow others to contribute to = the exact syntax and semantics, and finally a userland implementation = could reveal any potential hidden issues in the design before moving on = to a proper implementation in C for PHP core. -Mike P.S. If you are unfamiliar with how to implement in userland you can use = the same techniques I used in my proof-of-concept for Userland Packages: = https://github.com/mikeschinkel/userland-packages. If that link is not = enough and you instead want to ask specific questions about how to = implement in PHP, feel free to contact me off-list.