beberlei / assert

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

Is there a way to assert for known specific values? #323

Open dennis-fedco opened 2 years ago

dennis-fedco commented 2 years ago

Is there an efficient concise way to Assert for known possible values ahead of time, i.e. if a variable has values of either 0 or 1 (strings)? This is for a specific case with checkboxes.

But what about a more general case, like {alpha, beta, gamma, zetta}?

alejgarciarodriguez commented 1 year ago

Assertion::choice may helps

Assertion::choice(mixed $value, array $choices); Assertion::choicesNotEmpty(array $values, array $choices);