Skip to content

Commit

Permalink
Merge pull request #11 from faissaloux/tobenegative
Browse files Browse the repository at this point in the history
`toBeNegative()`
  • Loading branch information
faissaloux authored Jul 7, 2024
2 parents 7bcc89f + f951620 commit 382f61e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,9 @@ This plugin afford math related expectations.
expect(1)->toBePositive();
expect(-2)->not->toBePositive();
```

#### `toBeNegative()`
```php
expect(-1)->toBeNegative();
expect(2)->not->toBeNegative();
```
8 changes: 8 additions & 0 deletions src/Expectation.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ public function toBePositive(): PestExpectation
return expect($this->value > 0)->toBeTrue();
}

/**
* @return PestExpectation<TValue>
*/
public function toBeNegative(): PestExpectation
{
return expect($this->value < 0)->toBeTrue();
}

/**
* @return PestExpectation<TValue>
*/
Expand Down
19 changes: 19 additions & 0 deletions tests/toBeNegative.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

use PHPUnit\Framework\ExpectationFailedException;

it('passes', function (int $number): void {
expect($number)->toBeNegative();
})->with([-1, -2, -3, -4, -5, -6]);

it('passes not', function (int $number): void {
expect($number)->not->toBeNegative();
})->with([1, 2, 3, 4, 5, 6]);

test('failures', function (): void {
expect(0)->toBeNegative();
})->throws(ExpectationFailedException::class);

test('failures not', function (): void {
expect(-2)->not->toBeNegative();
})->throws(ExpectationFailedException::class);

0 comments on commit 382f61e

Please sign in to comment.