On Mon, Jul 15, 2024, at 21:23, Tim Düsterhus wrote:
> Hi
>
> On 7/12/24 08:00, Rob Landers wrote:
> > For what it’s worth, I see “resetAsLazy()” being most useful for unit testing
> > libraries that build proxies. While this feature will remove most of the tricky nuances around
> > proxies, it doesn’t make it any easier in generating the code for them, so that has to be tested.
> > Being able to write a test like this (abbreviated):
> >
> > $realObj = new $foo()
> > $proxy = clone $realObj;
> > makeTestProxy($proxy); // resets as lazy with initializer
> > assert($realObj == $proxy);
> >
> > Is really simple. Without a reset method, this isn’t straightforward.
> >
>
> I'm not sure if I follow this example. With the native support for lazy
> objects there should no longer be a need for code generation, no?
> Testing that PHP works correctly in your own test suite is not a
> value-add, PHP has its own tests for that.
>
> Best regards
> Tim Düsterhus
>
There are ghost objects, and then there are proxies. This RFC allows both. Beyond that, there are
many types of proxies. For example, I have a library that proxies an interface or class, generates a
spy proxy, and when the user calls those methods on it, it records these calls for asynchronous RPC
(for remote objects) or locally — kinda like erlang.
This code obviously has to be tested, both the generation of the code, as well as the execution. Now
that properties can exist on interfaces, I also have to figure out how that will affect things as
well, and test that. Being able to defer generation and/or state hydration to actual usage will be a
massive improvement, especially in cases where you may have nested objects.
Now, you asked why I would want to test PHP’s own behavior? Well, it’s a new language feature.
I’m going to test the hell out of it, learn its edges, and make sure it works as advertised and my
use case. If I find any bugs, I will report them. If this feature had existed for years, I would
probably still test it to make sure php upgrades don’t break expected behavior and it still works
on lower PHP versions. Are you suggesting that I don’t need to have tests for this, that PHP will
never change this feature?
— Rob