-
-
Notifications
You must be signed in to change notification settings - Fork 419
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
Handle Carbon macros #301
Handle Carbon macros #301
Conversation
8f40638
to
08ce439
Compare
Very well done. Could you make the test pass? |
@szepeviktor See my comment. On my local machine the tests are all green rather I tests with or without my change, and in Travis-CI it's like ignored. But in real apps, it's working. I can't guess more how the feature test is supposed to work. |
I guess tests are not compatible with Windows as running |
I found what was not compatible with Windows:
Now I get the tests working on my local machine, I will check the change has not the same effect in the test app than in my local app. |
Now, it needs a way to declare Carbon::macro('foo', static function (): string {
return 'foo';
}); Such macros should be callable both statically or dynamically. And not only in Carbon but also in the Laravel Macroable stuff. |
I see |
It should be marked as static and ignore “dynamic call to static method” in
phpstan.neon.
On Wed, 21 Aug 2019 at 11:13, Kyle ***@***.***> wrote:
I see $this->isStatic = false; inside the Macro which is incorrect. They
can be both. And we can consider a best practice to use static function
to declare them as static, but even without the static statement, macros
are callable statically, so they should more likely be considered static by
default.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#301>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAAZTOE7XWSZKV3Y5BOWDPTQFUBLPANCNFSM4IN5FDKA>
.
--
Ondřej Mirtes
|
I think it already is, as calling dynamically the static method do not raise errors. I proposed here a softer change that will only mark static macros if they are created with static closures. If behavior is changed for all macros it can be an other PR/discussion. |
@szepeviktor seems like there is a broken hook: But as I just updated the branch with master it means it's the same exact code than for the |
@@ -24,7 +24,7 @@ | |||
}, | |||
"require-dev": { | |||
"orchestra/testbench": "^3.8", | |||
"phpunit/phpunit": "^8.2" | |||
"phpunit/phpunit": "^7.3 || ^8.2" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a fix for 443f0fe
In order to have successful unit tests.
Hi,
I would like to propose a compatibility support for Carbon macros, it uses the same public API as Laravel macros but is different internally.
I tested the code above in Laravel apps and it works fine.
But I couldn't get a correct unit tests I mimicked other ones but if I revert my change in source, the
CarbonExtension
test still pass while I should get "undefined method" PHPStan errors.If you're OK to include this feature, could you help me to write this unit test?