-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can I patch DateTime? #146
Comments
Thank you for filing the issue! Strangely enough, the feature in question has gone undocumented up to this day. I will get to that as soon as I can. Please put the following in your {
"new-keyword-redefinable": true
} Once this is in check, redefine as follows: redefine('new DateTime', always(new \DateTime('18:10 30-11-2023'))); |
Thank you! Any ideas about the autoloading problem? |
I'm getting another error... Did you mean this should work as you indicated and you only need to update the docs, or is there a patch you need to submit? After the changes you suggested, I get this error:
Do I need to include anything other than |
This was a bug after all. Please update to 2.1.27 and retry. |
Thank you for your effort. Unfortunately, now I get two different errors. One of them only seemed to happen two or three times after trying to run the library in my test without dumping the autoloader.
This happens as long as I don't remove the entry in the files array in the Composer file and dump the autoloader, which tells me there is something going on with the autoload mechanism or the initialization of the library. |
Thank you for trying out the patch. It does seem that we are on the right track. When Please try adding |
This is the error now:
I think this is also the other error I saw earlier but just a few times. |
For the time being, could you try blacklisting The error that you report reveals an important shortcoming of the constructor redefinition component in all current versions of Patchwork. Thank you for bringing it to light. Unfortunately, this also means that it will take a little bit longer for me to arrive at a satisfactory fix. |
I also added "/workspace/vendor/symfony/dependency-injection/Loader/PhpFileLoader.php" and it finally stop failing; unfortunately, it doesn't seem to be doing what I was expecting (return the same fixed date for new DateTime), so I'm gonna stop trying to incorporate in our project for now. I'll be happy to provide you with more context if this is something you want to look into. |
@antecedent I'm curious if you ever managed to work this out? I'm working a project (Durable PHP), and it's really easy to forget to NOT use |
I'm trying to mock DateTime to capture some output, but I get this error:
I do it like this:
redefine('DateTime::__construct', always(new \DateTime('18:10 30-11-2023')));
And this my patchwork.json:
Should this work or am I trying something impossible?
Also, I installed the library via Composer but I still had to modify composer.json so it is autoloaded:
I'm using version 2.1.26. Thank you in advance!
The text was updated successfully, but these errors were encountered: