Repository navigation
Expand file tree
/
Copy pathFormConfigTest.php
More file actions
53 lines (41 loc) · 1.8 KB
/
Copy pathFormConfigTest.php
File metadata and controls
53 lines (41 loc) · 1.8 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
51
52
53
<?php
declare(strict_types=1);
use Illuminate\Database\Eloquent\Model;
use NyonCode\WireForms\Forms\Config\FormConfig;
test('config is immutable with defaults', function () {
$config = new FormConfig;
expect($config->schema)->toBe([])
->and($config->statePath)->toBeNull()
->and($config->model)->toBeNull()
->and($config->mutateDataBeforeSave)->toBeNull()
->and($config->beforeSave)->toBeNull()
->and($config->afterSave)->toBeNull()
->and($config->using)->toBeNull()
->and($config->successMessage)->toBe('__default__')
->and($config->validationMessages)->toBe([])
->and($config->isDisabled)->toBeFalse();
});
test('isCreating returns true for class-string model', function () {
$config = new FormConfig(model: 'App\\Models\\User');
expect($config->isCreating())->toBeTrue()
->and($config->isEditing())->toBeFalse()
->and($config->hasModel())->toBeTrue();
});
test('isEditing returns true for model instance', function () {
// Use a mock to simulate an Eloquent model
$model = Mockery::mock(Model::class);
$config = new FormConfig(model: $model);
expect($config->isEditing())->toBeTrue()
->and($config->isCreating())->toBeFalse()
->and($config->hasModel())->toBeTrue();
});
test('hasModel returns false when null', function () {
$config = new FormConfig(model: null);
expect($config->hasModel())->toBeFalse();
});
test('getModel returns the bound model for the FormConfigContract seam', function () {
$model = Mockery::mock(Model::class);
expect((new FormConfig(model: 'App\\Models\\User'))->getModel())->toBe('App\\Models\\User')
->and((new FormConfig(model: $model))->getModel())->toBe($model)
->and((new FormConfig(model: null))->getModel())->toBeNull();
});