mirror of
https://github.com/pestphp/pest.git
synced 2026-09-05 22:33:35 +02:00
136 lines
3.9 KiB
PHP
136 lines
3.9 KiB
PHP
<?php
|
|
|
|
use Pest\Repositories\DatasetsRepository;
|
|
|
|
it('show only the names of named datasets in their description', function (): void {
|
|
$descriptions = array_keys(DatasetsRepository::resolve([
|
|
[
|
|
'one' => [1],
|
|
'two' => [[2]],
|
|
],
|
|
], __FILE__));
|
|
|
|
expect($descriptions[0])->toBe('dataset "one"')
|
|
->and($descriptions[1])->toBe('dataset "two"');
|
|
});
|
|
|
|
it('show the actual dataset of non-named datasets in their description', function (): void {
|
|
$descriptions = array_keys(DatasetsRepository::resolve([
|
|
[
|
|
[1],
|
|
[[2]],
|
|
],
|
|
], __FILE__));
|
|
|
|
expect($descriptions[0])->toBe('(1)')
|
|
->and($descriptions[1])->toBe('([2])');
|
|
});
|
|
|
|
it('show only the names of multiple named datasets in their description', function (): void {
|
|
$descriptions = array_keys(DatasetsRepository::resolve([
|
|
[
|
|
'one' => [1],
|
|
'two' => [[2]],
|
|
],
|
|
[
|
|
'three' => [3],
|
|
'four' => [[4]],
|
|
],
|
|
], __FILE__));
|
|
|
|
expect($descriptions[0])->toBe('dataset "one" / dataset "three"')
|
|
->and($descriptions[1])->toBe('dataset "one" / dataset "four"')
|
|
->and($descriptions[2])->toBe('dataset "two" / dataset "three"')
|
|
->and($descriptions[3])->toBe('dataset "two" / dataset "four"');
|
|
});
|
|
|
|
it('show the actual dataset of multiple non-named datasets in their description', function (): void {
|
|
$descriptions = array_keys(DatasetsRepository::resolve([
|
|
[
|
|
[1],
|
|
[[2]],
|
|
],
|
|
[
|
|
[3],
|
|
[[4]],
|
|
],
|
|
], __FILE__));
|
|
|
|
expect($descriptions[0])->toBe('(1) / (3)')
|
|
->and($descriptions[1])->toBe('(1) / ([4])')
|
|
->and($descriptions[2])->toBe('([2]) / (3)')
|
|
->and($descriptions[3])->toBe('([2]) / ([4])');
|
|
});
|
|
|
|
it('show the correct description for mixed named and not-named datasets', function (): void {
|
|
$descriptions = array_keys(DatasetsRepository::resolve([
|
|
[
|
|
'one' => [1],
|
|
[[2]],
|
|
],
|
|
[
|
|
[3],
|
|
'four' => [[4]],
|
|
],
|
|
], __FILE__));
|
|
|
|
expect($descriptions[0])->toBe('dataset "one" / (3)')
|
|
->and($descriptions[1])->toBe('dataset "one" / dataset "four"')
|
|
->and($descriptions[2])->toBe('([2]) / (3)')
|
|
->and($descriptions[3])->toBe('([2]) / dataset "four"');
|
|
});
|
|
|
|
it('shows the correct description for long texts with newlines', function (): void {
|
|
$descriptions = array_keys(DatasetsRepository::resolve([
|
|
[
|
|
['some very \nlong text with \n newlines'],
|
|
],
|
|
], __FILE__));
|
|
|
|
expect($descriptions[0])->toBe('(\'some very long text with …wlines\')');
|
|
});
|
|
|
|
it('shows the correct description for arrays with many elements', function (): void {
|
|
$descriptions = array_keys(DatasetsRepository::resolve([
|
|
[
|
|
[[1, 2, 3, 4, 5]],
|
|
],
|
|
], __FILE__));
|
|
|
|
expect($descriptions[0])->toBe('([1, 2, 3, …])');
|
|
});
|
|
|
|
it('shows the correct description of datasets with html', function (): void {
|
|
$descriptions = array_keys(DatasetsRepository::resolve([
|
|
[
|
|
'<div class="flex items-center"></div>',
|
|
],
|
|
], __FILE__));
|
|
|
|
expect($descriptions[0])->toBe('(\'<div class="flex items-center"></div>\')');
|
|
});
|
|
|
|
it('does not treat a two element dataset of class names as a callable', function (): void {
|
|
$datasets = DatasetsRepository::resolve([
|
|
[
|
|
MagicCallDataset::class,
|
|
AnotherMagicCallDataset::class,
|
|
],
|
|
], __FILE__);
|
|
|
|
expect(array_values($datasets))->toBe([
|
|
[MagicCallDataset::class],
|
|
[AnotherMagicCallDataset::class],
|
|
]);
|
|
});
|
|
|
|
class MagicCallDataset
|
|
{
|
|
public static function __callStatic(string $name, array $arguments): void
|
|
{
|
|
throw new RuntimeException('This dataset should not be called.');
|
|
}
|
|
}
|
|
|
|
class AnotherMagicCallDataset {}
|