File tree Expand file tree Collapse file tree 2 files changed +15
-8
lines changed
packages/view/src/Components
tests/Integration/View/Components Expand file tree Collapse file tree 2 files changed +15
-8
lines changed Original file line number Diff line number Diff line change 88 */
99
1010use Tempest \Http \Session \Session ;
11+ use Tempest \Validation \Validator ;
1112
1213use function Tempest \get ;
1314use function Tempest \Support \str ;
1415
1516/** @var Session $session */
1617$ session = get (Session::class);
1718
19+ /** @var Validator $validator */
20+ $ validator = get (Validator::class);
21+
1822$ label ??= str ($ name )->title ();
1923$ id ??= $ name ;
2024$ type ??= 'text ' ;
3034 <textarea :if="$type === 'textarea'" :name="$name" :id="$id">{{ $original }}</textarea>
3135 <input :else :type="$type" :name="$name" :id="$id" :value="$original"/>
3236
33- <div :if="$errors !== []">
34- <div :foreach="$errors as $error">
35- {{ $error->message( ) }}
36- </div >
37- </div >
37+ <ul :if="$errors !== []">
38+ <li :foreach="$errors as $error">
39+ {{ $validator->getErrorMessage($error ) }}
40+ </li >
41+ </ul >
3842</div>
Original file line number Diff line number Diff line change 66use Tempest \Validation \Rules \IsInteger ;
77use Tempest \Validation \Rules \IsString ;
88use Tempest \Validation \Rules \Length ;
9+ use Tempest \Validation \Validator ;
910use Tests \Tempest \Integration \FrameworkIntegrationTestCase ;
1011
1112final class InputComponentTest extends FrameworkIntegrationTestCase
@@ -88,8 +89,10 @@ public function test_error_message(): void
8889
8990 $ html = $ this ->render ('<x-input name="name" /> ' );
9091
91- $ this ->assertStringContainsString (new IsString ()->message (), $ html );
92- $ this ->assertStringContainsString (new Length (min: 5 )->message (), $ html );
93- $ this ->assertStringNotContainsString (new IsInteger ()->message (), $ html );
92+ $ validator = $ this ->container ->get (Validator::class);
93+
94+ $ this ->assertStringContainsString ($ validator ->getErrorMessage (new IsString ()), $ html );
95+ $ this ->assertStringContainsString ($ validator ->getErrorMessage (new Length (min: 5 )), $ html );
96+ $ this ->assertStringNotContainsString ($ validator ->getErrorMessage (new IsInteger ()), $ html );
9497 }
9598}
You can’t perform that action at this time.
0 commit comments