[feat] scoped datasets

This commit is contained in:
Fabio Ivona
2022-09-19 17:45:27 +02:00
parent 12618ff8b3
commit cbee6e76b0
16 changed files with 267 additions and 40 deletions

View File

@ -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');

View File

@ -0,0 +1,5 @@
<?php
dataset('numbers.array', [
1, 2, 3, 4, 5, 'ScopedDatasets/Datasets/Scoped.php',
]);

View File

@ -0,0 +1,5 @@
<?php
dataset('numbers.array', [
1, 2, 3, 4, 5, 'ScopedDatasets/NestedDirectory1/Datasets.php',
]);

View 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('12345ScopedDatasets/NestedDirectory1/Datasets.php');
});

View 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('12345ScopedDatasets/Datasets/Scoped.php');
});

View File

@ -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');
});

View 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('12345ScopedDatasets/Datasets/Scoped.php');
});

View 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');
});