This repository has been archived by the owner on Jun 16, 2021. It is now read-only.
generated from pestphp/pest-plugin-template
-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from lukeraymonddowning/master
Adds a `sequence` method for traversable values
- Loading branch information
Showing
2 changed files
with
72 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,41 @@ | ||
<?php | ||
|
||
test('an exception is thrown if the the type is not iterable', function () { | ||
expect('Foobar')->each->sequence(); | ||
})->throws(BadMethodCallException::class, 'Expectation value is not traversable.'); | ||
|
||
test('allows for sequences of checks to be run on traversable data', function () { | ||
expect([1, 2, 3]) | ||
->each | ||
->sequence( | ||
function ($expectation) { $expectation->toBeInt()->toEqual(1); }, | ||
function ($expectation) { $expectation->toBeInt()->toEqual(2); }, | ||
function ($expectation) { $expectation->toBeInt()->toEqual(3); }, | ||
); | ||
|
||
expect(static::getCount())->toBe(6); | ||
}); | ||
|
||
test('loops back to the start if it runs out of sequence items', function () { | ||
expect([1, 2, 3, 1, 2, 3, 1, 2]) | ||
->each | ||
->sequence( | ||
function ($expectation) { $expectation->toBeInt()->toEqual(1); }, | ||
function ($expectation) { $expectation->toBeInt()->toEqual(2); }, | ||
function ($expectation) { $expectation->toBeInt()->toEqual(3); }, | ||
); | ||
|
||
expect(static::getCount())->toBe(16); | ||
}); | ||
|
||
test('it works if the number of items in the traversable is smaller than the number of expectations', function () { | ||
expect([1, 2]) | ||
->each | ||
->sequence( | ||
function ($expectation) { $expectation->toBeInt()->toEqual(1); }, | ||
function ($expectation) { $expectation->toBeInt()->toEqual(2); }, | ||
function ($expectation) { $expectation->toBeInt()->toEqual(3); }, | ||
); | ||
|
||
expect(static::getCount())->toBe(4); | ||
}); |