mirror of
https://github.com/pestphp/pest.git
synced 2026-03-11 10:17:23 +01:00
[feat] scoped datasets
This commit is contained in:
@ -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');
|
||||
});
|
||||
Reference in New Issue
Block a user