beberlei / assert

Thin assertion library for use in libraries and business-model
Other
2.41k stars 186 forks source link

Assertion::keySet #297

Open fracz opened 4 years ago

fracz commented 4 years ago

What do you think about an assertion that validates if the array meets the specified set of keys?

Assertion::keySet(['a' => 1], ['a']); // ok
Assertion::keySet(['a' => 1], ['a', 'b']); // not ok
Assertion::keySet(['a' => 1, 'b' => 1], ['a']); // not ok

Inspired by https://respect-validation.readthedocs.io/en/1.1/rules/KeySet/