Fix dataset name creation with objects

fixes #98
This commit is contained in:
johannes.pichler
2020-06-19 12:29:20 +02:00
parent 283d8f3e03
commit 0738e113ad
3 changed files with 39 additions and 17 deletions

View File

@ -75,11 +75,13 @@ final class Datasets
} }
$namedData = []; $namedData = [];
$number = 1;
foreach ($data as $values) { foreach ($data as $values) {
$values = is_array($values) ? $values : [$values]; $values = is_array($values) ? $values : [$values];
$name = $description . self::getDataSetDescription($values); $name = $description . sprintf(' #%d', $number) . self::getDataSetDescription($values);
$namedData[$name] = $values; $namedData[$name] = $values;
$number++;
} }
return $namedData; return $namedData;

View File

@ -22,25 +22,29 @@
✓ it throws exception if dataset already exist ✓ it throws exception if dataset already exist
✓ it sets closures ✓ it sets closures
✓ it sets arrays ✓ it sets arrays
✓ it gets bound to test case object with ('a') ✓ it gets bound to test case object #1 with ('a')
✓ it gets bound to test case object with ('b') ✓ it gets bound to test case object #2 with ('b')
✓ it truncates the description with ('FoooFoooFoooFoooFoooFoooFoooF...ooFooo') ✓ it truncates the description #1 with ('FoooFoooFoooFoooFoooFoooFoooF...ooFooo')
✓ lazy datasets with (1) ✓ lazy datasets #1 with (1)
✓ lazy datasets with (2) ✓ lazy datasets #2 with (2)
✓ lazy datasets did the job right ✓ lazy datasets did the job right
✓ eager datasets with (1) ✓ eager datasets #1 with (1)
✓ eager datasets with (2) ✓ eager datasets #2 with (2)
✓ eager datasets did the job right ✓ eager datasets did the job right
✓ lazy registered datasets with (1) ✓ lazy registered datasets #1 with (1)
✓ lazy registered datasets with (2) ✓ lazy registered datasets #2 with (2)
✓ lazy registered datasets did the job right ✓ lazy registered datasets did the job right
✓ eager registered datasets with (1) ✓ eager registered datasets #1 with (1)
✓ eager registered datasets with (2) ✓ eager registered datasets #2 with (2)
✓ eager registered datasets did the job right ✓ eager registered datasets did the job right
✓ eager wrapped registered datasets with (1) ✓ eager wrapped registered datasets #1 with (1)
✓ eager wrapped registered datasets with (2) ✓ eager wrapped registered datasets #2 with (2)
✓ eager registered wrapped datasets did the job right ✓ eager registered wrapped datasets did the job right
✓ lazy named datasets with (Bar Object (...)) ✓ lazy named datasets #1 with (Bar Object (...))
✓ it creates unique test case names #1 with ('Name 1', Pest\Plugin Object (), true)
✓ it creates unique test case names #2 with ('Name 1', Pest\Plugin Object (), true)
✓ it creates unique test case names #3 with ('Name 1', Pest\Plugin Object (), false)
✓ it creates unique test case names - count
PASS Tests\Features\Exceptions PASS Tests\Features\Exceptions
✓ it gives access the the underlying expectException ✓ it gives access the the underlying expectException
@ -144,5 +148,5 @@
WARN Tests\Visual\Success WARN Tests\Visual\Success
s visual snapshot of test suite on success s visual snapshot of test suite on success
Tests: 6 skipped, 79 passed Tests: 6 skipped, 83 passed
Time: 3.44s Time: 3.59s

View File

@ -3,6 +3,7 @@
use Pest\Datasets; use Pest\Datasets;
use Pest\Exceptions\DatasetAlreadyExist; use Pest\Exceptions\DatasetAlreadyExist;
use Pest\Exceptions\DatasetDoesNotExist; use Pest\Exceptions\DatasetDoesNotExist;
use Pest\Plugin;
it('throws exception if dataset does not exist', function () { it('throws exception if dataset does not exist', function () {
$this->expectException(DatasetDoesNotExist::class); $this->expectException(DatasetDoesNotExist::class);
@ -106,3 +107,18 @@ $namedDatasets = [
test('lazy named datasets', function ($text) use ($state, $datasets) { test('lazy named datasets', function ($text) use ($state, $datasets) {
assertTrue(true); assertTrue(true);
})->with($namedDatasets); })->with($namedDatasets);
$counter = 0;
it('creates unique test case names', function (string $name, Plugin $plugin, bool $bool) use (&$counter) {
assertTrue(true);
$counter++;
})->with([
['Name 1', new Plugin(), true],
['Name 1', new Plugin(), true],
['Name 1', new Plugin(), false],
]);
it('creates unique test case names - count', function () use (&$counter) {
assertEquals(3, $counter);
});