rezzza / TimeTraveler

Time traveling php library (pretty similar to ruby timecop)
103 stars 11 forks source link

Question: Why not ditch the extension and use go-aop? #21

Closed adri closed 9 years ago

adri commented 9 years ago

Thank you for this library! I like to ask if you know go-aop-php and if yes, why is AOP PHP used instead?

I'm using a similar technique in php-vcr and it works quite well for mocking arbitrary functions.

shouze commented 9 years ago

@adri looks like interesting I will try it in a separate branch, thx!

adri commented 9 years ago

Cool :-) good luck.

stephpy commented 9 years ago

Hi,

I looked at this library, which looks like awesome, but in documentation we can see:

I can suppose that most of programmers will argue that it’s impossible to intercept system function without extensions such as runkit. Yes, it’s absolutely true that we can not change the function that already loaded into the memory of PHP. However there is a small loophole in the PHP that can be exploited for free.

See here.

Here, aop php extension allow to override php functions/classes. Go-AOP does not allow it.

adri commented 9 years ago

Just read a little further :-)

Go! AOP framework has an experimental support for system function interception from the version 0.4.0. This means that there is an ability to create an advice for system functions!

stephpy commented 9 years ago

oh oops. :)

shouze commented 9 years ago

@adri I guess you refer to things explained in this very interesting article. Here's one excerpt:

Go! AOP framework has an experimental support for system function interception from the version 0.4.0. This means that there is an ability to create an advice for system functions!

Function interception can be very-very slow, so please do not try to intercept all system functions in all namespaces. However it’s so amazing

So ok we see it's for test purpose only or very very precise interception. With that indeed we should be able to intercept all calls to the following system php functions:

But... it remains the \DateTime object... I guess we have to check that we can intercept its own constructor call prior to go for a POC.

adri commented 9 years ago

Go-aop can't overwrite that class?

In php-vcr we overwrite the \SoapClient in a similar way, like here https://github.com/php-vcr/php-vcr/blob/master/tests/VCR/CodeTransform/SoapCodeTransformTest.php. Should be possible in a way with go-aop too.

I also advise to only use this for test or development purposes.

shouze commented 9 years ago

@adri ok thx to point out for \SoapClient so yes looks like checklist is good enough for a POC GO ;)