Skip to content

Commit f0bb570

Browse files
authored
Merge pull request #25 from faissaloux/tobeminof
`toBeMinOf()`
2 parents 6d150d6 + 2b4d8b9 commit f0bb570

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

Diff for: README.md

+6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ This plugin afford math related expectations.
2424
expect(5.5)->not->toBeMaxOf([2, 4.2, 5.5, 6]);
2525
```
2626

27+
#### `toBeMinOf()`
28+
```php
29+
expect(-6)->toBeMinOf([-6, 0, 1]);
30+
expect(5.5)->not->toBeMinOf([2, 4.2, 5.5, 6]);
31+
```
32+
2733
#### `toBeEven()`
2834
```php
2935
expect(6)->toBeEven();

Diff for: src/Expectation.php

+9
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,13 @@ public function toBeMaxOf(array $stack): PestExpectation
144144
{
145145
return expect($this->value === max($stack))->toBeTrue();
146146
}
147+
148+
/**
149+
* @param array<int|float> $stack
150+
* @return PestExpectation<TValue>
151+
*/
152+
public function toBeMinOf(array $stack): PestExpectation
153+
{
154+
return expect($this->value === min($stack))->toBeTrue();
155+
}
147156
}

Diff for: tests/toBeMinOf.php

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
use PHPUnit\Framework\ExpectationFailedException;
4+
5+
it('passes', function (int|float $value, array $stack): void {
6+
expect($value)->toBeMinOf($stack);
7+
})->with([
8+
[-6, [-6, 0, 1]],
9+
[-6, [-6, -2, -1]],
10+
[2.4, [2.4, 4.2, 6]],
11+
]);
12+
13+
it('passes not', function (int|float $value, array $stack): void {
14+
expect($value)->not->toBeMinOf($stack);
15+
})->with([
16+
[4, [2, 4, 6]],
17+
[0, [2, 4]],
18+
[5.5, [2, 4.2, 5.5, 6]],
19+
]);
20+
21+
test('failures', function (): void {
22+
expect(4)->toBeMinOf([2, 4, 6]);
23+
})->throws(ExpectationFailedException::class);
24+
25+
test('failures not', function (): void {
26+
expect(2)->not->toBeMinOf([2, 4, 6]);
27+
})->throws(ExpectationFailedException::class);

0 commit comments

Comments
 (0)