refacto: structure

This commit is contained in:
Nuno Maduro
2021-12-05 14:40:08 +00:00
parent e64b6fe924
commit b1f9ce2283
17 changed files with 79 additions and 61 deletions

View File

@ -1,9 +1,9 @@
<?php
use Pest\Datasets;
use Pest\Exceptions\DatasetAlreadyExist;
use Pest\Exceptions\DatasetDoesNotExist;
use Pest\Plugin;
use Pest\Repositories\DatasetsRepository;
beforeEach(function () {
$this->foo = 'bar';
@ -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']);`.");
Datasets::resolve('foo', ['first']);
DatasetsRepository::resolve('foo', ['first']);
});
it('throws exception if dataset already exist', function () {
Datasets::set('second', [[]]);
DatasetsRepository::set('second', [[]]);
$this->expectException(DatasetAlreadyExist::class);
$this->expectExceptionMessage('A dataset with the name `second` already exist.');
Datasets::set('second', [[]]);
DatasetsRepository::set('second', [[]]);
});
it('sets closures', function () {
Datasets::set('foo', function () {
DatasetsRepository::set('foo', function () {
yield [1];
});
expect(Datasets::resolve('foo', ['foo']))->toBe(['foo with (1)' => [1]]);
expect(DatasetsRepository::resolve('foo', ['foo']))->toBe(['foo with (1)' => [1]]);
});
it('sets arrays', function () {
Datasets::set('bar', [[2]]);
DatasetsRepository::set('bar', [[2]]);
expect(Datasets::resolve('bar', ['bar']))->toBe(['bar with (2)' => [2]]);
expect(DatasetsRepository::resolve('bar', ['bar']))->toBe(['bar with (2)' => [2]]);
});
it('gets bound to test case object', function () {

View File

@ -2,6 +2,7 @@
declare(strict_types=1);
use Pest\Exceptions\ExpectationNotFound;
use function PHPUnit\Framework\assertEquals;
use function PHPUnit\Framework\assertEqualsIgnoringCase;
use function PHPUnit\Framework\assertInstanceOf;

View File

@ -1,9 +1,9 @@
<?php
use Pest\Datasets;
use Pest\Repositories\DatasetsRepository;
it('show only the names of named datasets in their description', function () {
$descriptions = array_keys(Datasets::resolve('test description', [
$descriptions = array_keys(DatasetsRepository::resolve('test description', [
[
'one' => [1],
'two' => [[2]],
@ -15,7 +15,7 @@ it('show only the names of named datasets in their description', function () {
});
it('show the actual dataset of non-named datasets in their description', function () {
$descriptions = array_keys(Datasets::resolve('test description', [
$descriptions = array_keys(DatasetsRepository::resolve('test description', [
[
[1],
[[2]],
@ -27,7 +27,7 @@ it('show the actual dataset of non-named datasets in their description', functio
});
it('show only the names of multiple named datasets in their description', function () {
$descriptions = array_keys(Datasets::resolve('test description', [
$descriptions = array_keys(DatasetsRepository::resolve('test description', [
[
'one' => [1],
'two' => [[2]],
@ -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(Datasets::resolve('test description', [
$descriptions = array_keys(DatasetsRepository::resolve('test description', [
[
[1],
[[2]],
@ -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(Datasets::resolve('test description', [
$descriptions = array_keys(DatasetsRepository::resolve('test description', [
[
'one' => [1],
[[2]],