Extend array assertions - #18
Conversation
|
Could you add also |
webmozart
left a comment
There was a problem hiding this comment.
Thanks, sounds useful to me! :)
Can you please add the corresponding @method lines in the PhpDoc of the class? (look at the existing ones for example)
As for inArray(), there is oneOf() which fulfills this purpose.
| `keyExists($array, $key, $message = '')` | Check that a key exists in an array | ||
| `keyNotExists($array, $key, $message = '')` | Check that a key does not exist in an array | ||
| `keyNotExists($array, $key, $message = '')` | Check that a key does not exist in an | ||
| `count($array, $number, $message = '')` | Check that an array contains specific number of elements |
There was a problem hiding this comment.
Grammar: "contains a specific number of elements"
| static::eq( | ||
| count($array), | ||
| $number, | ||
| $message ?: sprintf('Array should have %d elements, but has %d.', $number, count($array)) |
There was a problem hiding this comment.
For consistency with the other exception messages, I'd change this to:
Expected an array to contain %d elements. Got: %d
6842a83 to
625049b
Compare
625049b to
2126e92
Compare
|
@webmozart fixed, hope it is perfect now ;) |
| ------------------------------------------- | -------------------------------------------------- | ||
| `keyExists($array, $key, $message = '')` | Check that a key exists in an array | ||
| `keyNotExists($array, $key, $message = '')` | Check that a key does not exist in an array | ||
| `keyNotExists($array, $key, $message = '')` | Check that a key does not exist in an |
There was a problem hiding this comment.
"Check that a key does not exist in an array"
You are missing "array"
There was a problem hiding this comment.
:( gonna fix it asap
2126e92 to
0c782e0
Compare
|
@webmozart sorry for the delay with last fixes (in fact, I was 100% sure I pushed them few days ago 😄 ). Hope really everything is now good and mergeable 👍 |
Count assert function. Will replace #18
|
Replaced by #24 |
Hello everybody!
First of all, I'd like to thank you for the amazing job with this library, it really fits my needs, I get used to use it and don't think I would like to change it at all 😄
As my contribution for this library development, I would propose introducing some more assertions associated with arrays. Starting from the simple
Assert::count(...)-> from my experience it would be pretty useful, as now to check array length, you musteqwithcount($array)which just looks bad 🐃Let me know is it something that could be useful for this library. Thank you for feedback and see ya in code ;)