-
-
Notifications
You must be signed in to change notification settings - Fork 13
Add Conditionable traits & phpdoc #37
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
Conversation
…ativePHP/desktop into feature/make-all-facades-conditionable
PeteBishwhip
left a comment
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.
Looks good. Worth a test to verify and assert the functionality remains and doesn't regress? :)
|
Sure 👍🏻 What sort of test do you have in mind? I'm only dropping in a trait here that is already covered by Laravel. So you must be meaning to test the integration with the existing logic? We can't do a full end-to-end test with Electron for this. We can do assertions on a mock object to see if methods were called, but I don't think those will be very valuable. Do you have any suggestions on how to cover regressions @PeteBishwhip ? Keen to know your vantage point |
|
To me, I think some tests don't have to test functionality as much as ensure certain traits. For example, I have a test in my own repos which simply make sure that all classes in a specific namespace extend a specific class and fails if one doesn't. In this case, if we can dynamically pull a list of registered facades, iterate through and ensure they include the Conditional trait... Or even just iterate the directory of Facades and just verify Just a small little failsafe that ensures we remain consistent. I'm happy to pop in a test for it on this PR if you're happy for me to? :) |
|
Ah check I get what you're saying! Perfect 👌 no worries I'm already at it |
simonhamp
left a comment
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.
Beautiful! 😍
|
@PeteBishwhip Is this what you had in mind? |
|
Hmm the test don't pass with Method "toUseTrait" does not exist in string. pestphp/pest: 2.30.0 |
|
@gwleuverink - That would work but doesn't protect against future additions. My thoughts were more to do a full scan of src/Facades and iterate through all, ensuring that the implement Conditionable. This way, we can explicitly exclude a class if it should not include it, but by default, the test expects all and any newly created Facades to include it. Something like: The test: I haven't tested this, and I took ages typing it in the comments box because I'm silly but it should work. Whats your thoughts? |
|
I see what you mean. Sure I can do that for the facades. Not all of these in the list are facades though, I'll keep the others hardcoded. |
|
|
||
| })->skip(function () { | ||
| // Only run test when pest version is at least 3 | ||
| return version_compare(version(), '3.0.0', '<'); |
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.
The test was failing on prefer-lowest when using pest 2.
I admit that this workaround is a bit janky. But if this runs on the higher versions i think that is enough.
|
My understanding (albeit wrong looking back) was that we were adding Conditionable to all Facade insert faceplam emoji. If it's specific ones, not really a way to dynamically ensure that things include it. In that case, your solution is okay. |
|
Most of these classes also have a facade so what you propose would work! We only also have to mix in some additional classes 👍 let me see if I can make it work |
|
Okay @PeteBishwhip i came to the same conclusion after writing it. I'll have to exclude about the same amount of classes I could remove using the 'dynamic' method. Maybe as it is is best in retrospect |
|
Okay, no biggie. Was hoping for something to ensure standards moving forward but perhaps thats a project for the future :) |
|
I'm on board with the idea. It's just that about only half of these facades have a fluent api where the Conditionable trait makes sense. When I had the solution ready and done I reconsidered your previous comment 😅 |
This pull request adds the
Conditionabletrait to all Facades where it makes sense (omitted all that don't use fluent chaining)Conditionabletrait to the following classes, allowing the use ofwhenandunlessmethods for more expressive and concise conditional logic:AppAlertAutoUpdaterChildProcessClipboardDockNotificationFacade method annotations:
@methodannotations forwhenandunless, ensuring IDEs and static analysis tools are aware of the new methods:AppAlertAutoUpdaterChildProcessClipboardDockMenualready conditionable, not annotatedNotification