mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 15:57:21 +01:00
writed tests with multiple datasets
Took 1 hour 6 minutes
This commit is contained in:
@ -77,11 +77,13 @@ final class TestCall
|
||||
* Runs the current test multiple times with
|
||||
* each item of the given `iterable`.
|
||||
*
|
||||
* @param \Closure|iterable<int|string, mixed>|string $data
|
||||
* @param array<\Closure|iterable<int|string, mixed>|string> $data
|
||||
*/
|
||||
public function with($data): TestCall
|
||||
public function with(...$data): TestCall
|
||||
{
|
||||
$this->testCaseFactory->datasets[] = $data;
|
||||
foreach ($data as $dataset) {
|
||||
$this->testCaseFactory->datasets[] = $dataset;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -51,6 +51,45 @@
|
||||
✓ it creates unique test case names with ('Name 2', Pest\Plugin Object (), true)
|
||||
✓ it creates unique test case names with ('Name 1', Pest\Plugin Object (), true) #3
|
||||
✓ it creates unique test case names - count
|
||||
✓ lazy multiple datasets with (1) / (3)
|
||||
✓ lazy multiple datasets with (1) / (4)
|
||||
✓ lazy multiple datasets with (2) / (3)
|
||||
✓ lazy multiple datasets with (2) / (4)
|
||||
✓ lazy multiple datasets did the job right
|
||||
✓ eager multiple datasets with (1) / (3)
|
||||
✓ eager multiple datasets with (1) / (4)
|
||||
✓ eager multiple datasets with (2) / (3)
|
||||
✓ eager multiple datasets with (2) / (4)
|
||||
✓ eager multiple datasets did the job right
|
||||
✓ lazy registered multiple datasets with (1) / (1)
|
||||
✓ lazy registered multiple datasets with (1) / (2)
|
||||
✓ lazy registered multiple datasets with (2) / (1)
|
||||
✓ lazy registered multiple datasets with (2) / (2)
|
||||
✓ lazy registered multiple datasets did the job right
|
||||
✓ eager registered multiple datasets with (1) / (1)
|
||||
✓ eager registered multiple datasets with (1) / (2)
|
||||
✓ eager registered multiple datasets with (2) / (1)
|
||||
✓ eager registered multiple datasets with (2) / (2)
|
||||
✓ eager registered multiple datasets did the job right
|
||||
✓ eager wrapped registered multiple datasets with (1) / (1)
|
||||
✓ eager wrapped registered multiple datasets with (1) / (2)
|
||||
✓ eager wrapped registered multiple datasets with (2) / (1)
|
||||
✓ eager wrapped registered multiple datasets with (2) / (2)
|
||||
✓ eager wrapped registered multiple datasets did the job right
|
||||
✓ named multiple datasets with data set "one" / data set "three"
|
||||
✓ named multiple datasets with data set "one" / data set "four"
|
||||
✓ named multiple datasets with data set "two" / data set "three"
|
||||
✓ named multiple datasets with data set "two" / data set "four"
|
||||
✓ named multiple datasets did the job right
|
||||
✓ more than two datasets with (1) / (3) / (5)
|
||||
✓ more than two datasets with (1) / (3) / (6)
|
||||
✓ more than two datasets with (1) / (4) / (5)
|
||||
✓ more than two datasets with (1) / (4) / (6)
|
||||
✓ more than two datasets with (2) / (3) / (5)
|
||||
✓ more than two datasets with (2) / (3) / (6)
|
||||
✓ more than two datasets with (2) / (4) / (5)
|
||||
✓ more than two datasets with (2) / (4) / (6)
|
||||
✓ more than two datasets did the job right
|
||||
|
||||
PASS Tests\Features\Exceptions
|
||||
✓ it gives access the the underlying expectException
|
||||
@ -170,24 +209,9 @@
|
||||
PASS Tests\Unit\Datasets
|
||||
✓ it show only the names of named datasets in their description
|
||||
✓ it show the actual dataset of non-named datasets in their description
|
||||
✓ it generates a matrix with given datasets with data set "dataset_aa" / data set "dataset_ba" / ('bar', 'foo', 'baz')
|
||||
✓ it generates a matrix with given datasets with data set "dataset_aa" / data set "dataset_ba" / ('zip', 'zap', 'zop')
|
||||
✓ it generates a matrix with given datasets with data set "dataset_aa" / data set "dataset_bb" / ('bar', 'foo', 'baz')
|
||||
✓ it generates a matrix with given datasets with data set "dataset_aa" / data set "dataset_bb" / ('zip', 'zap', 'zop')
|
||||
✓ it generates a matrix with given datasets with data set "dataset_aa" / data set "dataset_bc" / ('bar', 'foo', 'baz')
|
||||
✓ it generates a matrix with given datasets with data set "dataset_aa" / data set "dataset_bc" / ('zip', 'zap', 'zop')
|
||||
✓ it generates a matrix with given datasets with data set "dataset_ab" / data set "dataset_ba" / ('bar', 'foo', 'baz')
|
||||
✓ it generates a matrix with given datasets with data set "dataset_ab" / data set "dataset_ba" / ('zip', 'zap', 'zop')
|
||||
✓ it generates a matrix with given datasets with data set "dataset_ab" / data set "dataset_bb" / ('bar', 'foo', 'baz')
|
||||
✓ it generates a matrix with given datasets with data set "dataset_ab" / data set "dataset_bb" / ('zip', 'zap', 'zop')
|
||||
✓ it generates a matrix with given datasets with data set "dataset_ab" / data set "dataset_bc" / ('bar', 'foo', 'baz')
|
||||
✓ it generates a matrix with given datasets with data set "dataset_ab" / data set "dataset_bc" / ('zip', 'zap', 'zop')
|
||||
✓ it generates a matrix with given datasets with data set "dataset_ac" / data set "dataset_ba" / ('bar', 'foo', 'baz')
|
||||
✓ it generates a matrix with given datasets with data set "dataset_ac" / data set "dataset_ba" / ('zip', 'zap', 'zop')
|
||||
✓ it generates a matrix with given datasets with data set "dataset_ac" / data set "dataset_bb" / ('bar', 'foo', 'baz')
|
||||
✓ it generates a matrix with given datasets with data set "dataset_ac" / data set "dataset_bb" / ('zip', 'zap', 'zop')
|
||||
✓ it generates a matrix with given datasets with data set "dataset_ac" / data set "dataset_bc" / ('bar', 'foo', 'baz')
|
||||
✓ it generates a matrix with given datasets with data set "dataset_ac" / data set "dataset_bc" / ('zip', 'zap', 'zop')
|
||||
✓ it show only the names of multiple named datasets in their description
|
||||
✓ it show the actual dataset of multiple non-named datasets in their description
|
||||
✓ it show the correct description for mixed named and not-named datasets
|
||||
|
||||
PASS Tests\Unit\Plugins\Version
|
||||
✓ it outputs the version when --version is used
|
||||
@ -238,5 +262,5 @@
|
||||
✓ it is a test
|
||||
✓ it uses correct parent class
|
||||
|
||||
Tests: 7 skipped, 138 passed
|
||||
Tests: 7 skipped, 162 passed
|
||||
|
||||
@ -137,3 +137,89 @@ it('creates unique test case names', function (string $name, Plugin $plugin, boo
|
||||
it('creates unique test case names - count', function () use (&$counter) {
|
||||
expect($counter)->toBe(6);
|
||||
});
|
||||
|
||||
$datasets_a = [[1], [2]];
|
||||
$datasets_b = [[3], [4]];
|
||||
|
||||
test('lazy multiple datasets', function ($text_a, $text_b) use ($state, $datasets_a, $datasets_b) {
|
||||
$state->text .= $text_a . $text_b;
|
||||
expect($datasets_a)->toContain([$text_a]);
|
||||
expect($datasets_b)->toContain([$text_b]);
|
||||
})->with($datasets_a, $datasets_b);
|
||||
|
||||
test('lazy multiple datasets did the job right', function () use ($state) {
|
||||
expect($state->text)->toBe('12121212121213142324');
|
||||
});
|
||||
|
||||
$state->text = '';
|
||||
|
||||
test('eager multiple datasets', function ($text_a, $text_b) use ($state, $datasets_a, $datasets_b) {
|
||||
$state->text .= $text_a . $text_b;
|
||||
expect($datasets_a)->toContain([$text_a]);
|
||||
expect($datasets_b)->toContain([$text_b]);
|
||||
})->with(function () use ($datasets_a) {
|
||||
return $datasets_a;
|
||||
})->with(function () use ($datasets_b) {
|
||||
return $datasets_b;
|
||||
});
|
||||
|
||||
test('eager multiple datasets did the job right', function () use ($state) {
|
||||
expect($state->text)->toBe('1212121212121314232413142324');
|
||||
});
|
||||
|
||||
test('lazy registered multiple datasets', function ($text_a, $text_b) use ($state, $datasets) {
|
||||
$state->text .= $text_a . $text_b;
|
||||
expect($datasets)->toContain([$text_a]);
|
||||
expect($datasets)->toContain([$text_b]);
|
||||
})->with('numbers.array')->with('numbers.array');
|
||||
|
||||
test('lazy registered multiple datasets did the job right', function () use ($state) {
|
||||
expect($state->text)->toBe('121212121212131423241314232411122122');
|
||||
});
|
||||
|
||||
test('eager registered multiple datasets', function ($text_a, $text_b) use ($state, $datasets) {
|
||||
$state->text .= $text_a . $text_b;
|
||||
expect($datasets)->toContain([$text_a]);
|
||||
expect($datasets)->toContain([$text_b]);
|
||||
})->with('numbers.array')->with('numbers.closure');
|
||||
|
||||
test('eager registered multiple datasets did the job right', function () use ($state) {
|
||||
expect($state->text)->toBe('12121212121213142324131423241112212211122122');
|
||||
});
|
||||
|
||||
test('eager wrapped registered multiple datasets', function ($text_a, $text_b) use ($state, $datasets) {
|
||||
$state->text .= $text_a . $text_b;
|
||||
expect($datasets)->toContain([$text_a]);
|
||||
expect($datasets)->toContain([$text_b]);
|
||||
})->with('numbers.closure.wrapped')->with('numbers.closure');
|
||||
|
||||
test('eager wrapped registered multiple datasets did the job right', function () use ($state) {
|
||||
expect($state->text)->toBe('1212121212121314232413142324111221221112212211122122');
|
||||
});
|
||||
|
||||
test('named multiple datasets', function ($text_a, $text_b) use ($state, $datasets_a, $datasets_b) {
|
||||
$state->text .= $text_a . $text_b;
|
||||
expect($datasets_a)->toContain([$text_a]);
|
||||
expect($datasets_b)->toContain([$text_b]);
|
||||
})->with([
|
||||
'one' => [1],
|
||||
'two' => [2],
|
||||
])->with([
|
||||
'three' => [3],
|
||||
'four' => [4],
|
||||
]);
|
||||
|
||||
test('named multiple datasets did the job right', function () use ($state) {
|
||||
expect($state->text)->toBe('121212121212131423241314232411122122111221221112212213142324');
|
||||
});
|
||||
|
||||
test('more than two datasets', function ($text_a, $text_b, $text_c) use ($state, $datasets_a, $datasets_b) {
|
||||
$state->text .= $text_a . $text_b . $text_c;
|
||||
expect($datasets_a)->toContain([$text_a]);
|
||||
expect($datasets_b)->toContain([$text_b]);
|
||||
expect([5, 6])->toContain($text_c);
|
||||
})->with($datasets_a, $datasets_b)->with([5, 6]);
|
||||
|
||||
test('more than two datasets did the job right', function () use ($state) {
|
||||
expect($state->text)->toBe('121212121212131423241314232411122122111221221112212213142324135136145146235236245246');
|
||||
});
|
||||
|
||||
@ -26,44 +26,56 @@ it('show the actual dataset of non-named datasets in their description', functio
|
||||
expect($descriptions[1])->toBe('test description with (array(2))');
|
||||
});
|
||||
|
||||
$state = new stdClass();
|
||||
$state->combinations = [
|
||||
['a', 'b', 'c', 1, 2, 'bar', 'foo', 'baz'],
|
||||
['a', 'b', 'c', 1, 2, 'zip', 'zap', 'zop'],
|
||||
['a', 'b', 'c', 3, 4, 'bar', 'foo', 'baz'],
|
||||
['a', 'b', 'c', 3, 4, 'zip', 'zap', 'zop'],
|
||||
['a', 'b', 'c', 5, 6, 'bar', 'foo', 'baz'],
|
||||
['a', 'b', 'c', 5, 6, 'zip', 'zap', 'zop'],
|
||||
['d', 'e', 'f', 1, 2, 'bar', 'foo', 'baz'],
|
||||
['d', 'e', 'f', 1, 2, 'zip', 'zap', 'zop'],
|
||||
['d', 'e', 'f', 3, 4, 'bar', 'foo', 'baz'],
|
||||
['d', 'e', 'f', 3, 4, 'zip', 'zap', 'zop'],
|
||||
['d', 'e', 'f', 5, 6, 'bar', 'foo', 'baz'],
|
||||
['d', 'e', 'f', 5, 6, 'zip', 'zap', 'zop'],
|
||||
['g', 'h', 'i', 1, 2, 'bar', 'foo', 'baz'],
|
||||
['g', 'h', 'i', 1, 2, 'zip', 'zap', 'zop'],
|
||||
['g', 'h', 'i', 3, 4, 'bar', 'foo', 'baz'],
|
||||
['g', 'h', 'i', 3, 4, 'zip', 'zap', 'zop'],
|
||||
['g', 'h', 'i', 5, 6, 'bar', 'foo', 'baz'],
|
||||
['g', 'h', 'i', 5, 6, 'zip', 'zap', 'zop'],
|
||||
];
|
||||
it('show only the names of multiple named datasets in their description', function () {
|
||||
$descriptions = array_keys(Datasets::resolve('test description', [
|
||||
[
|
||||
'one' => [1],
|
||||
'two' => [[2]],
|
||||
],
|
||||
[
|
||||
'three' => [3],
|
||||
'four' => [[4]],
|
||||
],
|
||||
]));
|
||||
|
||||
it('generates a matrix with given datasets', function ($a1, $a2, $a3, $b1, $b2, $c1, $c2, $c3) use ($state) {
|
||||
$combinations = $state->combinations;
|
||||
$set = $combinations[0];
|
||||
array_shift($combinations);
|
||||
$state->combinations = $combinations;
|
||||
expect($descriptions[0])->toBe('test description with data set "one" / data set "three"');
|
||||
expect($descriptions[1])->toBe('test description with data set "one" / data set "four"');
|
||||
expect($descriptions[2])->toBe('test description with data set "two" / data set "three"');
|
||||
expect($descriptions[3])->toBe('test description with data set "two" / data set "four"');
|
||||
});
|
||||
|
||||
expect([$a1, $a2, $a3, $b1, $b2, $c1, $c2, $c3])->toMatchArray($set);
|
||||
})->with([
|
||||
'dataset_aa' => ['a1' => 'a', 'a2' => 'b', 'a3' => 'c'],
|
||||
'dataset_ab' => ['a1' => 'd', 'a2' => 'e', 'a3' => 'f'],
|
||||
'dataset_ac' => ['a1' => 'g', 'a2' => 'h', 'a3' => 'i'],
|
||||
])->with([
|
||||
'dataset_ba' => ['b1' => 1, 'b2' => 2],
|
||||
'dataset_bb' => ['b1' => 3, 'b2' => 4],
|
||||
'dataset_bc' => ['b1' => 5, 'b2' => 6],
|
||||
])->with([
|
||||
['c1' => 'bar', 'c2' => 'foo', 'c3' => 'baz'],
|
||||
['c1' => 'zip', 'c2' => 'zap', 'c3' => 'zop'],
|
||||
]);
|
||||
it('show the actual dataset of multiple non-named datasets in their description', function () {
|
||||
$descriptions = array_keys(Datasets::resolve('test description', [
|
||||
[
|
||||
[1],
|
||||
[[2]],
|
||||
],
|
||||
[
|
||||
[3],
|
||||
[[4]],
|
||||
],
|
||||
]));
|
||||
|
||||
expect($descriptions[0])->toBe('test description with (1) / (3)');
|
||||
expect($descriptions[1])->toBe('test description with (1) / (array(4))');
|
||||
expect($descriptions[2])->toBe('test description with (array(2)) / (3)');
|
||||
expect($descriptions[3])->toBe('test description with (array(2)) / (array(4))');
|
||||
});
|
||||
|
||||
it('show the correct description for mixed named and not-named datasets', function () {
|
||||
$descriptions = array_keys(Datasets::resolve('test description', [
|
||||
[
|
||||
'one' => [1],
|
||||
[[2]],
|
||||
],
|
||||
[
|
||||
[3],
|
||||
'four' => [[4]],
|
||||
],
|
||||
]));
|
||||
|
||||
expect($descriptions[0])->toBe('test description with data set "one" / (3)');
|
||||
expect($descriptions[1])->toBe('test description with data set "one" / data set "four"');
|
||||
expect($descriptions[2])->toBe('test description with (array(2)) / (3)');
|
||||
expect($descriptions[3])->toBe('test description with (array(2)) / data set "four"');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user