mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
[feat] scoped datasets
This commit is contained in:
@ -29,7 +29,7 @@
|
||||
✓ it does not append CoversNothing to other methods
|
||||
✓ it throws exception if no class nor method has been found
|
||||
|
||||
PASS Tests\Features\Datasets
|
||||
PASS Tests\Features\DatasetsTests
|
||||
✓ it throws exception if dataset does not exist
|
||||
✓ it throws exception if dataset already exist
|
||||
✓ it sets closures
|
||||
@ -116,6 +116,7 @@
|
||||
✓ it will not resolve a closure if it is type hinted as a callable with (Closure Object (...)) #2
|
||||
✓ it can correctly resolve a bound dataset that returns an array with (Closure Object (...))
|
||||
✓ it can correctly resolve a bound dataset that returns an array but wants to be spread with (Closure Object (...))
|
||||
↓ forbids to define tests in Datasets dirs and Datasets.php files
|
||||
|
||||
PASS Tests\Features\Depends
|
||||
✓ first
|
||||
@ -663,6 +664,47 @@
|
||||
✓ get 'foo' → get 'bar' → expect true → toBeTrue
|
||||
✓ get 'foo' → expect true → toBeTrue
|
||||
|
||||
PASS Tests\Features\ScopedDatasets\Directory\NestedDirectory1\TestFileInNestedDirectoryWithDatasetsFile
|
||||
✓ uses dataset with (1)
|
||||
✓ uses dataset with (2)
|
||||
✓ uses dataset with (3)
|
||||
✓ uses dataset with (4)
|
||||
✓ uses dataset with (5)
|
||||
✓ uses dataset with ('ScopedDatasets/NestedDirector...ts.php')
|
||||
✓ the right dataset is taken
|
||||
|
||||
PASS Tests\Features\ScopedDatasets\Directory\NestedDirectory2\TestFileInNestedDirectory
|
||||
✓ uses dataset with (1)
|
||||
✓ uses dataset with (2)
|
||||
✓ uses dataset with (3)
|
||||
✓ uses dataset with (4)
|
||||
✓ uses dataset with (5)
|
||||
✓ uses dataset with ('ScopedDatasets/Datasets/Scoped.php')
|
||||
✓ the right dataset is taken
|
||||
|
||||
PASS Tests\Features\ScopedDatasets\Directory\TestFileWithLocallyDefinedDataset
|
||||
✓ uses dataset with (1)
|
||||
✓ uses dataset with (2)
|
||||
✓ uses dataset with (3)
|
||||
✓ uses dataset with (4)
|
||||
✓ uses dataset with (5)
|
||||
✓ uses dataset with ('ScopedDatasets/ScopedDatasets.php')
|
||||
✓ the right dataset is taken
|
||||
|
||||
PASS Tests\Features\ScopedDatasets\Directory\TestFileWithScopedDataset
|
||||
✓ uses dataset with (1)
|
||||
✓ uses dataset with (2)
|
||||
✓ uses dataset with (3)
|
||||
✓ uses dataset with (4)
|
||||
✓ uses dataset with (5)
|
||||
✓ uses dataset with ('ScopedDatasets/Datasets/Scoped.php')
|
||||
✓ the right dataset is taken
|
||||
|
||||
PASS Tests\Features\ScopedDatasets\TestFileOutOfScope
|
||||
✓ uses dataset with (1)
|
||||
✓ uses dataset with (2)
|
||||
✓ the right dataset is taken
|
||||
|
||||
WARN Tests\Features\Skip
|
||||
✓ it do not skips
|
||||
- it skips with truthy → 1
|
||||
@ -761,7 +803,7 @@
|
||||
PASS Tests\Unit\Console\Help
|
||||
✓ it outputs the help information when --help is used
|
||||
|
||||
PASS Tests\Unit\Datasets
|
||||
PASS Tests\Unit\DatasetsTests
|
||||
✓ it show only the names of named datasets in their description
|
||||
✓ it show the actual dataset of non-named datasets in their description
|
||||
✓ it show only the names of multiple named datasets in their description
|
||||
@ -818,4 +860,4 @@
|
||||
PASS Tests\Visual\Version
|
||||
✓ visual snapshot of help command output
|
||||
|
||||
Tests: 4 incomplete, 1 todo, 18 skipped, 562 passed (1460 assertions)
|
||||
Tests: 4 incomplete, 2 todos, 18 skipped, 593 passed (1503 assertions)
|
||||
@ -13,28 +13,28 @@ it('throws exception if dataset does not exist', function () {
|
||||
$this->expectException(DatasetDoesNotExist::class);
|
||||
$this->expectExceptionMessage("A dataset with the name `first` does not exist. You can create it using `dataset('first', ['a', 'b']);`.");
|
||||
|
||||
DatasetsRepository::resolve('foo', ['first']);
|
||||
DatasetsRepository::resolve(['first'], __FILE__);
|
||||
});
|
||||
|
||||
it('throws exception if dataset already exist', function () {
|
||||
DatasetsRepository::set('second', [[]]);
|
||||
DatasetsRepository::set('second', [[]], __DIR__);
|
||||
$this->expectException(DatasetAlreadyExist::class);
|
||||
$this->expectExceptionMessage('A dataset with the name `second` already exist.');
|
||||
DatasetsRepository::set('second', [[]]);
|
||||
$this->expectExceptionMessage('A dataset with the name `second` already exist in scope ['.__DIR__.'].');
|
||||
DatasetsRepository::set('second', [[]], __DIR__);
|
||||
});
|
||||
|
||||
it('sets closures', function () {
|
||||
DatasetsRepository::set('foo', function () {
|
||||
yield [1];
|
||||
});
|
||||
}, __DIR__);
|
||||
|
||||
expect(DatasetsRepository::resolve('foo', ['foo']))->toBe(['(1)' => [1]]);
|
||||
expect(DatasetsRepository::resolve(['foo'], __FILE__))->toBe(['(1)' => [1]]);
|
||||
});
|
||||
|
||||
it('sets arrays', function () {
|
||||
DatasetsRepository::set('bar', [[2]]);
|
||||
DatasetsRepository::set('bar', [[2]], __DIR__);
|
||||
|
||||
expect(DatasetsRepository::resolve('bar', ['bar']))->toBe(['(2)' => [2]]);
|
||||
expect(DatasetsRepository::resolve(['bar'], __FILE__))->toBe(['(2)' => [2]]);
|
||||
});
|
||||
|
||||
it('gets bound to test case object', function ($value) {
|
||||
@ -304,3 +304,5 @@ it('can correctly resolve a bound dataset that returns an array but wants to be
|
||||
return ['foo', 'bar', 'baz'];
|
||||
},
|
||||
]);
|
||||
|
||||
todo('forbids to define tests in Datasets dirs and Datasets.php files');
|
||||
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
dataset('numbers.array', [
|
||||
1, 2, 3, 4, 5, 'ScopedDatasets/Datasets/Scoped.php',
|
||||
]);
|
||||
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
dataset('numbers.array', [
|
||||
1, 2, 3, 4, 5, 'ScopedDatasets/NestedDirectory1/Datasets.php',
|
||||
]);
|
||||
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
$state = new stdClass();
|
||||
$state->text = '';
|
||||
test('uses dataset', function ($value) use ($state) {
|
||||
$state->text .= $value;
|
||||
expect(true)->toBe(true);
|
||||
})->with('numbers.array');
|
||||
|
||||
test('the right dataset is taken', function () use ($state) {
|
||||
expect($state->text)->toBe('12345ScopedDatasets/NestedDirectory1/Datasets.php');
|
||||
});
|
||||
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
$state = new stdClass();
|
||||
$state->text = '';
|
||||
test('uses dataset', function ($value) use ($state) {
|
||||
$state->text .= $value;
|
||||
expect(true)->toBe(true);
|
||||
})->with('numbers.array');
|
||||
|
||||
test('the right dataset is taken', function () use ($state) {
|
||||
expect($state->text)->toBe('12345ScopedDatasets/Datasets/Scoped.php');
|
||||
});
|
||||
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
dataset('numbers.array', [
|
||||
1, 2, 3, 4, 5, 'ScopedDatasets/ScopedDatasets.php',
|
||||
]);
|
||||
|
||||
$state = new stdClass();
|
||||
$state->text = '';
|
||||
test('uses dataset', function ($value) use ($state) {
|
||||
$state->text .= $value;
|
||||
expect(true)->toBe(true);
|
||||
})->with('numbers.array');
|
||||
|
||||
test('the right dataset is taken', function () use ($state) {
|
||||
expect($state->text)->toBe('12345ScopedDatasets/ScopedDatasets.php');
|
||||
});
|
||||
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
$state = new stdClass();
|
||||
$state->text = '';
|
||||
test('uses dataset', function ($value) use ($state) {
|
||||
$state->text .= $value;
|
||||
expect(true)->toBe(true);
|
||||
})->with('numbers.array');
|
||||
|
||||
test('the right dataset is taken', function () use ($state) {
|
||||
expect($state->text)->toBe('12345ScopedDatasets/Datasets/Scoped.php');
|
||||
});
|
||||
12
tests/Features/ScopedDatasets/TestFileOutOfScope.php
Normal file
12
tests/Features/ScopedDatasets/TestFileOutOfScope.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
$state = new stdClass();
|
||||
$state->text = '';
|
||||
test('uses dataset', function ($value) use ($state) {
|
||||
$state->text .= $value;
|
||||
expect(true)->toBe(true);
|
||||
})->with('numbers.array');
|
||||
|
||||
test('the right dataset is taken', function () use ($state) {
|
||||
expect($state->text)->toBe('12');
|
||||
});
|
||||
@ -3,31 +3,31 @@
|
||||
use Pest\Repositories\DatasetsRepository;
|
||||
|
||||
it('show only the names of named datasets in their description', function () {
|
||||
$descriptions = array_keys(DatasetsRepository::resolve('test description', [
|
||||
$descriptions = array_keys(DatasetsRepository::resolve([
|
||||
[
|
||||
'one' => [1],
|
||||
'two' => [[2]],
|
||||
],
|
||||
]));
|
||||
], __FILE__));
|
||||
|
||||
expect($descriptions[0])->toBe('data set "one"')
|
||||
->and($descriptions[1])->toBe('data set "two"');
|
||||
});
|
||||
|
||||
it('show the actual dataset of non-named datasets in their description', function () {
|
||||
$descriptions = array_keys(DatasetsRepository::resolve('test description', [
|
||||
$descriptions = array_keys(DatasetsRepository::resolve([
|
||||
[
|
||||
[1],
|
||||
[[2]],
|
||||
],
|
||||
]));
|
||||
], __FILE__));
|
||||
|
||||
expect($descriptions[0])->toBe('(1)');
|
||||
expect($descriptions[1])->toBe('(array(2))');
|
||||
});
|
||||
|
||||
it('show only the names of multiple named datasets in their description', function () {
|
||||
$descriptions = array_keys(DatasetsRepository::resolve('test description', [
|
||||
$descriptions = array_keys(DatasetsRepository::resolve([
|
||||
[
|
||||
'one' => [1],
|
||||
'two' => [[2]],
|
||||
@ -36,7 +36,7 @@ it('show only the names of multiple named datasets in their description', functi
|
||||
'three' => [3],
|
||||
'four' => [[4]],
|
||||
],
|
||||
]));
|
||||
], __FILE__));
|
||||
|
||||
expect($descriptions[0])->toBe('data set "one" / data set "three"');
|
||||
expect($descriptions[1])->toBe('data set "one" / data set "four"');
|
||||
@ -45,7 +45,7 @@ it('show only the names of multiple named datasets in their description', functi
|
||||
});
|
||||
|
||||
it('show the actual dataset of multiple non-named datasets in their description', function () {
|
||||
$descriptions = array_keys(DatasetsRepository::resolve('test description', [
|
||||
$descriptions = array_keys(DatasetsRepository::resolve([
|
||||
[
|
||||
[1],
|
||||
[[2]],
|
||||
@ -54,7 +54,7 @@ it('show the actual dataset of multiple non-named datasets in their description'
|
||||
[3],
|
||||
[[4]],
|
||||
],
|
||||
]));
|
||||
], __FILE__));
|
||||
|
||||
expect($descriptions[0])->toBe('(1) / (3)');
|
||||
expect($descriptions[1])->toBe('(1) / (array(4))');
|
||||
@ -63,7 +63,7 @@ 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', function () {
|
||||
$descriptions = array_keys(DatasetsRepository::resolve('test description', [
|
||||
$descriptions = array_keys(DatasetsRepository::resolve([
|
||||
[
|
||||
'one' => [1],
|
||||
[[2]],
|
||||
@ -72,7 +72,7 @@ it('show the correct description for mixed named and not-named datasets', functi
|
||||
[3],
|
||||
'four' => [[4]],
|
||||
],
|
||||
]));
|
||||
], __FILE__));
|
||||
|
||||
expect($descriptions[0])->toBe('data set "one" / (3)');
|
||||
expect($descriptions[1])->toBe('data set "one" / data set "four"');
|
||||
Reference in New Issue
Block a user