Compare commits

...

24 Commits

Author SHA1 Message Date
811ef27ee4 release: v2.24.0 2023-10-17 10:07:18 +01:00
22a7fd0656 chore: adjusts snapshots 2023-10-17 10:07:08 +01:00
698c276cbe chore: fixes style 2023-10-17 10:06:58 +01:00
6340656ece chore: bumps dependencies 2023-10-17 10:06:48 +01:00
2d5840f947 Merge pull request #933 from hungthai1401/throws_unless
[2.x] Add `throwsUnless`
2023-10-17 10:03:16 +01:00
b8bb3684a3 Merge pull request #983 from Muhammad-Sarfaraz/patch-1
Polishing Up "TestDox.php' PHPDoc Blocks for Clarity
2023-10-17 10:02:08 +01:00
b8cd563569 Update src/Factories/Annotations/TestDox.php
Co-authored-by: Owen Voke <development@voke.dev>
2023-10-16 16:23:09 +06:00
9fb64599de Polishing Up "TestDox.php' PHPDoc Blocks for Clarity
Added the missing parenthesis and period for proper punctuation and formatted the doc block to meet PHPDocumentor standards.
2023-10-16 10:56:06 +06:00
502f37d280 chore: updates links 2023-10-15 12:10:07 +01:00
29cfa8ec35 chore: updates sponsors 2023-10-14 11:34:00 +01:00
a63cd2e4f5 Merge pull request #980 from salehhashemi1992/fix/lifecycle-hook-scope
Fix TestCycle hook scope
2023-10-13 15:27:37 +01:00
7249b59e52 fix lifecycle hook scope 2023-10-13 17:51:02 +03:30
5c94d9994e Merge pull request #979 from salehhashemi1992/ci/checkout-update
Update actions/checkout to v4
2023-10-13 00:36:11 +01:00
bb0a5d8323 update checkout to v4 2023-10-12 21:32:46 +03:30
b126e8e6e4 release: v2.23.2 2023-10-10 16:40:34 +01:00
677129d23d chore: uses paratest 7.3.0 2023-10-10 16:39:04 +01:00
cef5c36885 release: v2.23.1 2023-10-10 15:57:14 +01:00
a343ba4a29 chore: adds PHPUnit 10.4.1 support 2023-10-10 15:57:07 +01:00
21b30b22a7 release: v2.23.0 2023-10-10 15:41:56 +01:00
449c4b6c5e chore: adds collision v8 support 2023-10-10 15:37:25 +01:00
6513ad6ced release: v2.22.1 2023-10-10 14:59:16 +01:00
12421c846e chore: adds termwind v2 support 2023-10-10 14:55:43 +01:00
e888f3613b refactor: change falsy to false 2023-08-24 16:40:30 +07:00
6c3d8829ce feat: throwsUnless method 2023-08-24 09:28:47 +07:00
15 changed files with 87 additions and 28 deletions

View File

@ -20,7 +20,7 @@ jobs:
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v4
- name: Setup PHP - name: Setup PHP
uses: shivammathur/setup-php@v2 uses: shivammathur/setup-php@v2

View File

@ -18,7 +18,7 @@ jobs:
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v4
- name: Setup PHP - name: Setup PHP
uses: shivammathur/setup-php@v2 uses: shivammathur/setup-php@v2

View File

@ -21,7 +21,7 @@ jobs:
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v4
- name: Setup PHP - name: Setup PHP
uses: shivammathur/setup-php@v2 uses: shivammathur/setup-php@v2

View File

@ -32,7 +32,6 @@ We cannot thank our sponsors enough for their incredible support in funding Pest
- [Codecourse](https://codecourse.com/) - [Codecourse](https://codecourse.com/)
- [Laracasts](https://laracasts.com/) - [Laracasts](https://laracasts.com/)
- [Localazy](https://localazy.com) - [Localazy](https://localazy.com)
- [Fathom Analytics](https://usefathom.com/)
- [Meema](https://meema.io) - [Meema](https://meema.io)
- [Zapiet](https://www.zapiet.com) - [Zapiet](https://www.zapiet.com)

View File

@ -18,15 +18,15 @@
], ],
"require": { "require": {
"php": "^8.1.0", "php": "^8.1.0",
"brianium/paratest": "^7.2.9", "brianium/paratest": "^7.3.0",
"nunomaduro/collision": "^7.9.0", "nunomaduro/collision": "^7.10.0|^8.0.0",
"nunomaduro/termwind": "^1.15.1", "nunomaduro/termwind": "^1.15.1|^2.0.0",
"pestphp/pest-plugin": "^2.1.1", "pestphp/pest-plugin": "^2.1.1",
"pestphp/pest-plugin-arch": "^2.3.3", "pestphp/pest-plugin-arch": "^2.4.1",
"phpunit/phpunit": "^10.4.0" "phpunit/phpunit": "^10.4.1"
}, },
"conflict": { "conflict": {
"phpunit/phpunit": ">10.4.0", "phpunit/phpunit": ">10.4.1",
"sebastian/exporter": "<5.1.0", "sebastian/exporter": "<5.1.0",
"webmozart/assert": "<1.11.0" "webmozart/assert": "<1.11.0"
}, },

View File

@ -23,9 +23,10 @@ final class Thanks
* @var array<string, string> * @var array<string, string>
*/ */
private const FUNDING_MESSAGES = [ private const FUNDING_MESSAGES = [
'Star the project on GitHub' => 'https://github.com/pestphp/pest', 'Star' => 'https://github.com/pestphp/pest',
'Tweet about the project' => 'https://twitter.com/pestphp', 'News' => 'https://twitter.com/pestphp',
'Sponsor the project' => 'https://github.com/sponsors/nunomaduro', 'Videos' => 'https://youtube.com/@nunomaduro',
'Sponsor' => 'https://github.com/sponsors/nunomaduro',
]; ];
/** /**

View File

@ -15,12 +15,11 @@ final class TestDox implements AddsAnnotations
public function __invoke(TestCaseMethodFactory $method, array $annotations): array public function __invoke(TestCaseMethodFactory $method, array $annotations): array
{ {
/* /*
* escapes docblock according to * Escapes docblock according to
* https://manual.phpdoc.org/HTMLframesConverter/default/phpDocumentor/tutorial_phpDocumentor.howto.pkg.html#basics.desc * https://manual.phpdoc.org/HTMLframesConverter/default/phpDocumentor/tutorial_phpDocumentor.howto.pkg.html#basics.desc
* *
* note: '@' escaping is not needed as it cannot be the first character of the line (it always starts with @testdox * Note: '@' escaping is not needed as it cannot be the first character of the line (it always starts with @testdox).
*/ */
assert($method->description !== null); assert($method->description !== null);
$methodDescription = str_replace('*/', '{@*}', $method->description); $methodDescription = str_replace('*/', '{@*}', $method->description);

View File

@ -105,6 +105,24 @@ final class TestCall
return $this; return $this;
} }
/**
* Asserts that the test throws the given `$exceptionClass` when called if the given condition is false.
*
* @param (callable(): bool)|bool $condition
*/
public function throwsUnless(callable|bool $condition, string|int $exception, string $exceptionMessage = null, int $exceptionCode = null): self
{
$condition = is_callable($condition)
? $condition
: static fn (): bool => $condition;
if (! $condition()) {
return $this->throws($exception, $exceptionMessage, $exceptionCode);
}
return $this;
}
/** /**
* Runs the current test multiple times with * Runs the current test multiple times with
* each item of the given `iterable`. * each item of the given `iterable`.

View File

@ -6,7 +6,7 @@ namespace Pest;
function version(): string function version(): string
{ {
return '2.22.0'; return '2.24.0';
} }
function testDirectory(string $file = ''): string function testDirectory(string $file = ''): string

View File

@ -1,5 +1,5 @@
Pest Testing Framework 2.22.0. Pest Testing Framework 2.24.0.
USAGE: pest <file> [options] USAGE: pest <file> [options]

View File

@ -1,3 +1,3 @@
Pest Testing Framework 2.22.0. Pest Testing Framework 2.24.0.

View File

@ -215,6 +215,14 @@
✓ it can just define the code if given condition is true ✓ it can just define the code if given condition is true
✓ it can just define the message if given condition is 1 ✓ it can just define the message if given condition is 1
✓ it can just define the code if given condition is 1 ✓ it can just define the code if given condition is 1
✓ it not catch exceptions if given condition is true
✓ it catch exceptions if given condition is false
✓ it catch exceptions and messages if given condition is false
✓ it catch exceptions, messages and code if given condition is false
✓ it can just define the message if given condition is false
✓ it can just define the code if given condition is false
✓ it can just define the message if given condition is 0
✓ it can just define the code if given condition is 0
PASS Tests\Features\Expect\HigherOrder\methods PASS Tests\Features\Expect\HigherOrder\methods
✓ it can access methods ✓ it can access methods
@ -1352,4 +1360,4 @@
WARN Tests\Visual\Version WARN Tests\Visual\Version
- visual snapshot of help command output - visual snapshot of help command output
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 19 skipped, 958 passed (2281 assertions) Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 19 skipped, 966 passed (2292 assertions)

View File

@ -59,3 +59,37 @@ it('can just define the message if given condition is 1', function () {
it('can just define the code if given condition is 1', function () { it('can just define the code if given condition is 1', function () {
throw new Exception('Something bad happened', 1); throw new Exception('Something bad happened', 1);
})->throwsIf(1, 1); })->throwsIf(1, 1);
it('not catch exceptions if given condition is true', function () {
$this->assertTrue(true);
})->throwsUnless(true, Exception::class);
it('catch exceptions if given condition is false', function () {
throw new Exception('Something bad happened');
})->throwsUnless(function () {
return false;
}, Exception::class);
it('catch exceptions and messages if given condition is false', function () {
throw new Exception('Something bad happened');
})->throwsUnless(false, Exception::class, 'Something bad happened');
it('catch exceptions, messages and code if given condition is false', function () {
throw new Exception('Something bad happened', 1);
})->throwsUnless(false, Exception::class, 'Something bad happened', 1);
it('can just define the message if given condition is false', function () {
throw new Exception('Something bad happened');
})->throwsUnless(false, 'Something bad happened');
it('can just define the code if given condition is false', function () {
throw new Exception('Something bad happened', 1);
})->throwsUnless(false, 1);
it('can just define the message if given condition is 0', function () {
throw new Exception('Something bad happened');
})->throwsUnless(0, 'Something bad happened');
it('can just define the code if given condition is 0', function () {
throw new Exception('Something bad happened', 1);
})->throwsUnless(0, 1);

View File

@ -8,16 +8,16 @@ $foo->beforeEach = false;
$foo->afterEach = false; $foo->afterEach = false;
$foo->afterAll = false; $foo->afterAll = false;
beforeAll(function () { beforeAll(function () use ($foo) {
$foo->beforeAll = true; $foo->beforeAll = true;
}); });
beforeEach(function () { beforeEach(function () use ($foo) {
$foo->beforeEach = true; $foo->beforeEach = true;
}); });
afterEach(function () { afterEach(function () use ($foo) {
$foo->afterEach = true; $foo->afterEach = true;
}); });
afterAll(function () { afterAll(function () use ($foo) {
$foo->afterAll = true; $foo->afterAll = true;
}); });

View File

@ -16,7 +16,7 @@ $run = function () {
test('parallel', function () use ($run) { test('parallel', function () use ($run) {
expect($run('--exclude-group=integration')) expect($run('--exclude-group=integration'))
->toContain('Tests: 1 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 15 skipped, 947 passed (2266 assertions)') ->toContain('Tests: 1 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 15 skipped, 955 passed (2277 assertions)')
->toContain('Parallel: 3 processes'); ->toContain('Parallel: 3 processes');
})->skipOnWindows(); })->skipOnWindows();