Skip to content

Commit 30daa6e

Browse files
authored
Simplify validation error tests
1 parent ccf2855 commit 30daa6e

File tree

1 file changed

+12
-57
lines changed

1 file changed

+12
-57
lines changed

tests/ServiceProviderTest.php

Lines changed: 12 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -75,76 +75,31 @@ public function test_validation_errors_are_not_registered_when_already_registere
7575
$this->assertSame('This is a validation error', Inertia::getShared('errors'));
7676
}
7777

78-
public function basicValidationErrorsProvider()
78+
public function test_validation_errors_are_returned_in_the_correct_format()
7979
{
80-
$array = [
80+
Session::put('errors', (new ViewErrorBag())->put('default', new MessageBag([
8181
'name' => 'The name field is required.',
82-
'email' => [
83-
'The email must be a valid email address.',
84-
],
85-
];
86-
87-
$messageBag = new MessageBag([
88-
'name' => 'The name field is required.',
89-
'email' => 'The email must be a valid email address.',
90-
]);
91-
92-
$viewErrorBag = (new ViewErrorBag())->put('default', new MessageBag([
93-
'name' => [
94-
'The name field is required.',
95-
],
96-
'email' => 'The email must be a valid email address.',
97-
]));
98-
99-
return [
100-
[$array],
101-
[$messageBag],
102-
[$viewErrorBag],
103-
];
104-
}
105-
106-
/**
107-
* @dataProvider basicValidationErrorsProvider
108-
*/
109-
public function test_validation_errors_are_returned_in_the_correct_format($errors)
110-
{
111-
Session::put('errors', $errors);
82+
'email' => 'Not a valid email address.',
83+
])));
11284

11385
$errors = Inertia::getShared('errors')();
11486

11587
$this->assertIsObject($errors);
11688
$this->assertSame('The name field is required.', $errors->name);
117-
$this->assertSame('The email must be a valid email address.', $errors->email);
89+
$this->assertSame('Not a valid email address.', $errors->email);
11890
}
11991

120-
public function test_validation_errors_can_have_multiple_error_bags()
92+
public function test_validation_errors_with_named_error_bags_are_scoped()
12193
{
122-
Session::put('errors', tap(new ViewErrorBag(), function ($errorBag) {
123-
$errorBag->put('default', new MessageBag([
124-
'name' => 'The name field is required.',
125-
'email' => 'The email must be a valid email address.',
126-
]));
127-
$errorBag->put('example', new MessageBag([
128-
'name' => 'The name field is required.',
129-
'email' => [
130-
'The email must be a valid email address.',
131-
],
132-
]));
133-
}));
134-
135-
$errors = Inertia::getShared('errors')();
136-
137-
$this->assertIsObject($errors);
138-
$this->assertSame('The name field is required.', $errors->default['name']);
139-
$this->assertSame('The email must be a valid email address.', $errors->example['email']);
140-
}
94+
Session::put('errors', (new ViewErrorBag())->put('example', new MessageBag([
95+
'name' => 'The name field is required.',
96+
'email' => 'Not a valid email address.',
97+
])));
14198

142-
public function test_validation_errors_will_be_empty_when_an_invalid_value_was_set_to_the_session()
143-
{
144-
Session::put('errors', new Request());
14599
$errors = Inertia::getShared('errors')();
146100

147101
$this->assertIsObject($errors);
148-
$this->assertEmpty(get_object_vars($errors));
102+
$this->assertSame('The name field is required.', $errors->example->name);
103+
$this->assertSame('Not a valid email address.', $errors->example->email);
149104
}
150105
}

0 commit comments

Comments
 (0)