-
Notifications
You must be signed in to change notification settings - Fork 148
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
Add implies as logical assertion #225
base: master
Are you sure you want to change the base?
Add implies as logical assertion #225
Conversation
Tests fail. I'll wait to hear feedback on this PR before I fix those. |
Could you please rebase this PR to make sure the tests are green? |
7a4dfaa
to
2314a37
Compare
This assertion can be used to easily assert stuff like: > Assert::implies($hasDog, $leashAttached); Which will assert that $leashAttached is true, if $hasDog is true. This is a shorthand for `Assert::true(!$hasDog || $leashAttached)`.
2314a37
to
9051325
Compare
Allright @Nyholm I rebased and squashed my commits. Tests are now green. Only the Code Coverage fails, but it looks like this is not related to what I have done.
|
to @ all what do you think about changing the signature to
I personally hate type coercion and think that negation of Thoughts? |
@zerkms I just copied what I already found out in the existing code base. However I think this is done to support stuff like:
I.e.: if there are people, there should be seats. Anyhow: let me know if I do need to change to booleans. |
^ this code expresses the domain requirement explicitly: if there are any people - then there should be some seats. To me
In other places some extra assertions should be applied then as well.
I'm just another contributor here and don't make decisions on my own :-) |
I extracted this logical assertion from our code-base. It helps us in cases where we want to assert transitions between the states something can be in. But it can be used in more situations.
This is en existing logical operator, see: https://en.wikipedia.org/wiki/Material_conditional. Not sure how well known it is, but it makes sense once you start using it.
So: let's say you want to assert the input of method
updateState($old, $new)
:You want it to only allow you to go from PENDING to ACTIVE, you can assert using:
Which in speech would translate to: If the old status is PENDING, the new status must be ACTIVE.
And you could also write this as follows, but note how that does not communicate the actual intent.
Or you want to assert that you can only reach TERMINATED either from ACTIVE or PENDING, that would be;
Which in speech would translate to: If the new status is TERMINATED the old status must be either ACTIVE or PENDING.
And you could also write this as follows:
Would love to hear if anybody thinks this is something you consider adding to this repo.