mirror of
https://github.com/pestphp/pest.git
synced 2026-03-10 17:57:23 +01:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e83667a20b | |||
| aa96d75fb9 | |||
| 57161ba5ad | |||
| b1a9254fc1 | |||
| d5097d0fe5 | |||
| 022ad4be0d | |||
| 4a9fb2fa74 | |||
| d8fae6d689 |
@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
|
|||||||
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||||
|
|
||||||
|
## [v1.14.0 (2021-08-03)](https://github.com/pestphp/pest/compare/v1.13.0...v1.14.0)
|
||||||
|
### Added
|
||||||
|
- A new bound closure that allows you to access the test case in Datasets ([#364](https://github.com/pestphp/pest/pull/364))
|
||||||
|
|
||||||
## [v1.13.0 (2021-08-02)](https://github.com/pestphp/pest/compare/v1.12.0...v1.13.0)
|
## [v1.13.0 (2021-08-02)](https://github.com/pestphp/pest/compare/v1.12.0...v1.13.0)
|
||||||
### Added
|
### Added
|
||||||
- A cleaner output when running the Pest runner in PhpStorm ([#350](https://github.com/pestphp/pest/pull/350))
|
- A cleaner output when running the Pest runner in PhpStorm ([#350](https://github.com/pestphp/pest/pull/350))
|
||||||
|
|||||||
@ -273,7 +273,19 @@ trait Testable
|
|||||||
*/
|
*/
|
||||||
public function __test()
|
public function __test()
|
||||||
{
|
{
|
||||||
return $this->__callClosure($this->__test, func_get_args());
|
return $this->__callClosure($this->__test, $this->resolveTestArguments(func_get_args()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolve the passed arguments. Any Closures will be bound to the testcase and resolved.
|
||||||
|
*
|
||||||
|
* @throws Throwable
|
||||||
|
*/
|
||||||
|
private function resolveTestArguments(array $arguments): array
|
||||||
|
{
|
||||||
|
return array_map(function ($data) {
|
||||||
|
return $data instanceof Closure ? $this->__callClosure($data, []) : $data;
|
||||||
|
}, $arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -6,7 +6,7 @@ namespace Pest;
|
|||||||
|
|
||||||
function version(): string
|
function version(): string
|
||||||
{
|
{
|
||||||
return '1.13.0';
|
return '1.14.0';
|
||||||
}
|
}
|
||||||
|
|
||||||
function testDirectory(string $file = ''): string
|
function testDirectory(string $file = ''): string
|
||||||
|
|||||||
@ -96,6 +96,11 @@
|
|||||||
✓ more than two datasets with (2) / (4) / (5)
|
✓ more than two datasets with (2) / (4) / (5)
|
||||||
✓ more than two datasets with (2) / (4) / (6)
|
✓ more than two datasets with (2) / (4) / (6)
|
||||||
✓ more than two datasets did the job right
|
✓ more than two datasets did the job right
|
||||||
|
✓ it can resolve a dataset after the test case is available with (Closure Object (...))
|
||||||
|
✓ it can resolve a dataset after the test case is available with shared yield sets with (Closure Object (...)) #1
|
||||||
|
✓ it can resolve a dataset after the test case is available with shared yield sets with (Closure Object (...)) #2
|
||||||
|
✓ it can resolve a dataset after the test case is available with shared array sets with (Closure Object (...)) #1
|
||||||
|
✓ it can resolve a dataset after the test case is available with shared array sets with (Closure Object (...)) #2
|
||||||
|
|
||||||
PASS Tests\Features\Exceptions
|
PASS Tests\Features\Exceptions
|
||||||
✓ it gives access the the underlying expectException
|
✓ it gives access the the underlying expectException
|
||||||
@ -614,5 +619,5 @@
|
|||||||
✓ it is a test
|
✓ it is a test
|
||||||
✓ it uses correct parent class
|
✓ it uses correct parent class
|
||||||
|
|
||||||
Tests: 4 incompleted, 9 skipped, 390 passed
|
Tests: 4 incompleted, 9 skipped, 395 passed
|
||||||
|
|
||||||
11
tests/Datasets/Bound.php
Normal file
11
tests/Datasets/Bound.php
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
dataset('bound.closure', function () {
|
||||||
|
yield function () { return 1; };
|
||||||
|
yield function () { return 2; };
|
||||||
|
});
|
||||||
|
|
||||||
|
dataset('bound.array', [
|
||||||
|
function () { return 1; },
|
||||||
|
function () { return 2; },
|
||||||
|
]);
|
||||||
@ -5,6 +5,10 @@ use Pest\Exceptions\DatasetAlreadyExist;
|
|||||||
use Pest\Exceptions\DatasetDoesNotExist;
|
use Pest\Exceptions\DatasetDoesNotExist;
|
||||||
use Pest\Plugin;
|
use Pest\Plugin;
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
$this->foo = 'bar';
|
||||||
|
});
|
||||||
|
|
||||||
it('throws exception if dataset does not exist', function () {
|
it('throws exception if dataset does not exist', function () {
|
||||||
$this->expectException(DatasetDoesNotExist::class);
|
$this->expectException(DatasetDoesNotExist::class);
|
||||||
$this->expectExceptionMessage("A dataset with the name `first` does not exist. You can create it using `dataset('first', ['a', 'b']);`.");
|
$this->expectExceptionMessage("A dataset with the name `first` does not exist. You can create it using `dataset('first', ['a', 'b']);`.");
|
||||||
@ -223,3 +227,17 @@ test('more than two datasets', function ($text_a, $text_b, $text_c) use ($state,
|
|||||||
test('more than two datasets did the job right', function () use ($state) {
|
test('more than two datasets did the job right', function () use ($state) {
|
||||||
expect($state->text)->toBe('121212121212131423241314232411122122111221221112212213142324135136145146235236245246');
|
expect($state->text)->toBe('121212121212131423241314232411122122111221221112212213142324135136145146235236245246');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can resolve a dataset after the test case is available', function ($result) {
|
||||||
|
expect($result)->toBe('bar');
|
||||||
|
})->with([
|
||||||
|
function () { return $this->foo; },
|
||||||
|
]);
|
||||||
|
|
||||||
|
it('can resolve a dataset after the test case is available with shared yield sets', function ($result) {
|
||||||
|
expect($result)->toBeInt()->toBeLessThan(3);
|
||||||
|
})->with('bound.closure');
|
||||||
|
|
||||||
|
it('can resolve a dataset after the test case is available with shared array sets', function ($result) {
|
||||||
|
expect($result)->toBeInt()->toBeLessThan(3);
|
||||||
|
})->with('bound.array');
|
||||||
|
|||||||
Reference in New Issue
Block a user