feat: adds fails

This commit is contained in:
Nuno Maduro
2023-12-28 10:31:39 +00:00
parent e00aba539a
commit f83d758d4b
3 changed files with 31 additions and 0 deletions

View File

@ -19,6 +19,7 @@ use Pest\Support\NullClosure;
use Pest\Support\Str; use Pest\Support\Str;
use Pest\TestSuite; use Pest\TestSuite;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\AssertionFailedError;
/** /**
* @internal * @internal
@ -57,6 +58,14 @@ final class TestCall
$this->testSuite->beforeEach->get($this->filename)[0]($this); $this->testSuite->beforeEach->get($this->filename)[0]($this);
} }
/**
* Asserts that the test fails with the given message.
*/
public function fails(?string $message = null): self
{
return $this->throws(AssertionFailedError::class, $message);
}
/** /**
* Asserts that the test throws the given `$exceptionClass` when called. * Asserts that the test throws the given `$exceptionClass` when called.
*/ */

11
tests/Features/Fail.php Normal file
View File

@ -0,0 +1,11 @@
<?php
use PHPUnit\Framework\AssertionFailedError;
it('may fail', function () {
$this->fail();
})->throws(AssertionFailedError::class);
it('may fail with the given message', function () {
$this->fail('this is a failure');
})->throws(AssertionFailedError::class, 'this is a failure');

11
tests/Features/Fails.php Normal file
View File

@ -0,0 +1,11 @@
<?php
use PHPUnit\Framework\AssertionFailedError;
it('may fail', function () {
$this->fail();
})->fails();
it('may fail with the given message', function () {
$this->fail('this is a failure');
})->fails('this is a failure');