Repository navigation
Expand file tree
/
Copy pathConfigBuilderTest.php
More file actions
50 lines (40 loc) · 1.6 KB
/
Copy pathConfigBuilderTest.php
File metadata and controls
50 lines (40 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
declare(strict_types=1);
use NyonCode\WireForms\Components\TextInput;
use NyonCode\WireForms\Forms\Config\ConfigBuilder;
test('builder accumulates fluent calls and builds config', function () {
$schema = [TextInput::make('name')];
$mutation = fn (array $data) => $data;
$config = (new ConfigBuilder)
->schema($schema)
->statePath('data')
->model('App\\Models\\User')
->mutateDataBeforeSave($mutation)
->validationMessages(['name.required' => 'Required!'])
->disabled()
->build();
expect($config->schema)->toHaveCount(1)
->and($config->statePath)->toBe('data')
->and($config->model)->toBe('App\\Models\\User')
->and($config->mutateDataBeforeSave)->toBe($mutation)
->and($config->validationMessages)->toBe(['name.required' => 'Required!'])
->and($config->isDisabled)->toBeTrue();
});
test('builder provides getters before building', function () {
$builder = (new ConfigBuilder)
->schema([TextInput::make('email')])
->statePath('form')
->model('App\\Models\\User');
expect($builder->getSchema())->toHaveCount(1)
->and($builder->getStatePath())->toBe('form')
->and($builder->getModel())->toBe('App\\Models\\User')
->and($builder->isDisabled())->toBeFalse();
});
test('each build creates fresh config', function () {
$builder = (new ConfigBuilder)->statePath('a');
$config1 = $builder->build();
$builder->statePath('b');
$config2 = $builder->build();
expect($config1->statePath)->toBe('a')
->and($config2->statePath)->toBe('b');
});