mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
feat(expect): handle property calls to opposite expectations
This commit is contained in:
@ -9,7 +9,7 @@ use PHPUnit\Framework\Assert;
|
|||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*
|
*
|
||||||
* @property Expectation $not Creates the opposite expectation.
|
* @property Expectation not Creates the opposite expectation.
|
||||||
*/
|
*/
|
||||||
final class Expectation
|
final class Expectation
|
||||||
{
|
{
|
||||||
|
|||||||
@ -42,4 +42,19 @@ final class OppositeExpectation
|
|||||||
|
|
||||||
throw new ExpectationFailedException(sprintf('@todo'));
|
throw new ExpectationFailedException(sprintf('@todo'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle dynamic properties gets into the original expectation.
|
||||||
|
*/
|
||||||
|
public function __get(string $name): Expectation
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
/* @phpstan-ignore-next-line */
|
||||||
|
$this->original->{$name};
|
||||||
|
} catch (ExpectationFailedException $e) {
|
||||||
|
return $this->original;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new ExpectationFailedException(sprintf('@todo'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,9 @@
|
|||||||
PASS Tests\CustomTestCase\ExecutedTest
|
PASS Tests\CustomTestCase\ExecutedTest
|
||||||
✓ that gets executed
|
✓ that gets executed
|
||||||
|
|
||||||
|
PASS Tests\Expect\not
|
||||||
|
✓ not property calls
|
||||||
|
|
||||||
PASS Tests\Expect\toBe
|
PASS Tests\Expect\toBe
|
||||||
✓ expect true → toBeTrue → and false → toBeFalse
|
✓ expect true → toBeTrue → and false → toBeFalse
|
||||||
✓ strict comparisons
|
✓ strict comparisons
|
||||||
@ -309,5 +312,5 @@
|
|||||||
WARN Tests\Visual\Success
|
WARN Tests\Visual\Success
|
||||||
- visual snapshot of test suite on success
|
- visual snapshot of test suite on success
|
||||||
|
|
||||||
Tests: 6 skipped, 182 passed
|
Tests: 6 skipped, 183 passed
|
||||||
Time: 5.72s
|
Time: 5.77s
|
||||||
|
|||||||
10
tests/Expect/not.php
Normal file
10
tests/Expect/not.php
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
test('not property calls', function () {
|
||||||
|
expect(true)
|
||||||
|
->toBeTrue()
|
||||||
|
->not()->toBeFalse()
|
||||||
|
->not->toBeFalse
|
||||||
|
->and(false)
|
||||||
|
->toBeFalse();
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user