assert icon indicating copy to clipboard operation
assert copied to clipboard

Need chaining assertions with allow fails.

Open Lexty opened this issue 10 years ago • 0 comments

It may look like

\Assert\ThatOneOf($someObject, 'Value must be string or object with method "__toString".')
    ->string()
    ->methodExists($someObject, '__toString')
    ->end();

This chain fails only if both assertions fails. I know this check can be realize as it described in #83.

try {
    Assert::string($someObject);
} catch (AssertionFailedException $e) {
    Assert::methodExists($someObject, '__toString');
}

But if we need more assertions next looks better.

\Assert\ThatOneOf($x, '-30 < x < -20 || -10 < x < 10 || 20 < x < 30 || 40 < x < 50')
    ->range(-30, -20)
    ->range(-10,  10)
    ->range( 20,  30)
    ->range( 40,  50)
    ->end();

What do you think about it?

Lexty avatar Aug 26 '15 12:08 Lexty