mirror of
https://github.com/pestphp/pest.git
synced 2026-03-12 02:37:22 +01:00
Merge branch 'master' into nested-higher-order-expectations
# Conflicts: # tests/.snapshots/success.txt
This commit is contained in:
@ -127,7 +127,7 @@ final class Expectation
|
|||||||
|
|
||||||
if (is_callable($callback)) {
|
if (is_callable($callback)) {
|
||||||
foreach ($this->value as $item) {
|
foreach ($this->value as $item) {
|
||||||
$callback(expect($item));
|
$callback(new self($item));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,8 +136,12 @@ final class Expectation
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows you to specify a sequential set of expectations for each item in a iterable "value".
|
* Allows you to specify a sequential set of expectations for each item in a iterable "value".
|
||||||
|
*
|
||||||
|
* @template TValue
|
||||||
|
*
|
||||||
|
* @param callable(self, self): void|TValue ...$callbacks
|
||||||
*/
|
*/
|
||||||
public function sequence(callable ...$callbacks): Expectation
|
public function sequence(...$callbacks): Expectation
|
||||||
{
|
{
|
||||||
if (!is_iterable($this->value)) {
|
if (!is_iterable($this->value)) {
|
||||||
throw new BadMethodCallException('Expectation value is not iterable.');
|
throw new BadMethodCallException('Expectation value is not iterable.');
|
||||||
@ -155,7 +159,12 @@ final class Expectation
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach ($values as $key => $item) {
|
foreach ($values as $key => $item) {
|
||||||
call_user_func($callbacks[$key], expect($item), expect($keys[$key]));
|
if (is_callable($callbacks[$key])) {
|
||||||
|
call_user_func($callbacks[$key], new self($item), new self($keys[$key]));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
(new self($item))->toEqual($callbacks[$key]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|||||||
@ -111,11 +111,9 @@
|
|||||||
✓ it works inside of each
|
✓ it works inside of each
|
||||||
✓ it works with sequence
|
✓ it works with sequence
|
||||||
✓ it can compose complex expectations
|
✓ it can compose complex expectations
|
||||||
✓ it can handle nested method calls
|
|
||||||
|
|
||||||
PASS Tests\Features\Expect\HigherOrder\methodsAndProperties
|
PASS Tests\Features\Expect\HigherOrder\methodsAndProperties
|
||||||
✓ it can access methods and properties
|
✓ it can access methods and properties
|
||||||
✓ it can handle nested methods and properties
|
|
||||||
|
|
||||||
PASS Tests\Features\Expect\HigherOrder\properties
|
PASS Tests\Features\Expect\HigherOrder\properties
|
||||||
✓ it allows properties to be accessed from the value
|
✓ it allows properties to be accessed from the value
|
||||||
@ -126,7 +124,6 @@
|
|||||||
✓ it works with sequence
|
✓ it works with sequence
|
||||||
✓ it can compose complex expectations
|
✓ it can compose complex expectations
|
||||||
✓ it works with objects
|
✓ it works with objects
|
||||||
✓ it works with nested properties
|
|
||||||
|
|
||||||
PASS Tests\Features\Expect\each
|
PASS Tests\Features\Expect\each
|
||||||
✓ an exception is thrown if the the type is not iterable
|
✓ an exception is thrown if the the type is not iterable
|
||||||
@ -159,6 +156,8 @@
|
|||||||
✓ loops back to the start if it runs out of sequence items
|
✓ loops back to the start if it runs out of sequence items
|
||||||
✓ it works if the number of items in the iterable is smaller than the number of expectations
|
✓ it works if the number of items in the iterable is smaller than the number of expectations
|
||||||
✓ it works with associative arrays
|
✓ it works with associative arrays
|
||||||
|
✓ it can be passed non-callable values
|
||||||
|
✓ it can be passed a mixture of value types
|
||||||
|
|
||||||
PASS Tests\Features\Expect\toBe
|
PASS Tests\Features\Expect\toBe
|
||||||
✓ strict comparisons
|
✓ strict comparisons
|
||||||
@ -576,5 +575,5 @@
|
|||||||
✓ it is a test
|
✓ it is a test
|
||||||
✓ it uses correct parent class
|
✓ it uses correct parent class
|
||||||
|
|
||||||
Tests: 4 incompleted, 7 skipped, 360 passed
|
Tests: 4 incompleted, 7 skipped, 359 passed
|
||||||
|
|
||||||
@ -44,3 +44,19 @@ test('it works with associative arrays', function () {
|
|||||||
function ($expectation, $key) { $expectation->toEqual('boom'); $key->toEqual('baz'); },
|
function ($expectation, $key) { $expectation->toEqual('boom'); $key->toEqual('baz'); },
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('it can be passed non-callable values', function () {
|
||||||
|
expect(['foo', 'bar', 'baz'])->sequence('foo', 'bar', 'baz');
|
||||||
|
|
||||||
|
expect(static::getCount())->toBe(3);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('it can be passed a mixture of value types', function () {
|
||||||
|
expect(['foo', 'bar', 'baz'])->sequence(
|
||||||
|
'foo',
|
||||||
|
function ($expectation) { $expectation->toEqual('bar')->toBeString(); },
|
||||||
|
'baz'
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(static::getCount())->toBe(4);
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user