-
-
Notifications
You must be signed in to change notification settings - Fork 360
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
use PHPUnit\Framework\ExpectationFailedException; | ||
|
||
expect(true)->toBeTrue()->and(false)->toBeFalse(); | ||
|
||
test('risky with no assertions', function () { | ||
expect(1)->toBeOneOf(); | ||
})->throwsNoExceptions(); | ||
|
||
test('to be one of', function () { | ||
expect(1)->toBeOneOf(fn ($e) => $e->toBe(1), fn ($e) => $e->toBe(2), fn ($e) => $e->toBe(3)); | ||
}); | ||
|
||
test('it does not short-circuit', function () { | ||
$executed = 0; | ||
expect(1)->toBeOneOf(function ($e) use (&$executed) { | ||
$executed++; | ||
|
||
return $e->toBe(1); | ||
}, function ($e) use (&$executed) { | ||
$executed++; | ||
|
||
return $e->toBe(2); | ||
}, function ($e) use (&$executed) { | ||
$executed++; | ||
|
||
return $e->toBe(3); | ||
}); | ||
|
||
expect($executed)->toBe(3); | ||
}); | ||
|
||
test('failure with multiple matches', function () { | ||
expect(1)->toBeOneOf(fn ($e) => $e->toBe(1), fn ($e) => $e->toBe(1)); | ||
})->throws(ExpectationFailedException::class, 'Failed asserting value matches exactly one expectation (matches: 0, 1).'); | ||
|
||
test('failure with no matches', function () { | ||
expect(1)->toBeOneOf(fn ($e) => $e->toBe(2), fn ($e) => $e->toBe(2)); | ||
})->throws(ExpectationFailedException::class, 'Failed asserting value matches any expectations.'); |