-
-
Notifications
You must be signed in to change notification settings - Fork 7
Add support to dot notation in toHaveKey expectation #15
Conversation
…dot-notation-in-toHaveKey # Conflicts: # src/Helpers/Arr.php
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 amazing and simple, just had some minor comments 👍
Just updated code to address @olivernybroe comments |
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.
Really nice, could we add a test for the error message also, in case someone tries to refactor it to assertTrue
with a custom message, but doesn't realise that it adds two lines 👍
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.
LGTM!
Thanks for the great work ❤️
Done, I updated failures tests adding the exceptionMessage check:
also I refactored the whole test file, using a dataset would not have been compatible with the |
hmm, seems there is an issue with composer dependencies.. is it something I can solve myself? |
hmm @owenvoke could you help out with the composer issues that @fabio-ivona is having? 😃 |
Oh, it's the old circular dependencies issue. 😦 I'm not actually sure how to resolve that. I think I opened PRs a while back that helped fix it by basically adding I'll open a PR in a bit to see if I can get it fixed. |
This tests issue will be fixed once we merge all plugins on the core. @owenvoke Is taking care of that. |
That's fine for me At this point I don't think this PR needs more work from me, let me know if you need something else ;) |
@lukeraymonddowning Can you please perform this pull request on the core? |
This PR wants to add support for dot notation when giving the array key to test with
expect()->toHaveKey()
expectationthis will allow to write a test like this one:
As you can see in the last expectation of the example, In order to not be a breaking change, this implementation still allows to address an array key containing a dot in the string.
some credits:
to parse dot notated keys I added an helper
Arr
static class, taking inspiration forhas()
andget()
methods implementation from the laravel/framework project@olivernybroe gave me the nice idea of allowing arrays with dots in it to obtain a non-breaking change
bonus: while adding these new tests cases to the
tests/Expect/toHaveKey.php
tests, I noticed that the second assertion oftoHaveKey($key, $value)
expectation (assert that the array has that specific value for the given key) was never tested, so added tests for it as well