Skip to content

Commit 5fdcc4d

Browse files
committed
Check version to define validation message
1 parent 3336ddf commit 5fdcc4d

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

tests/ValidationTest.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Barryvdh\Form\Facade\FormFactory;
66
use Barryvdh\Form\Tests\Types\ParentFormType;
77
use Barryvdh\Form\Tests\Types\UserFormType;
8+
use Illuminate\Foundation\Application;
89
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
910
use Symfony\Component\Form\FormInterface;
1011
use Symfony\Component\HttpFoundation\Request;
@@ -69,7 +70,12 @@ public function testInvalidEmailForm()
6970

7071
$this->assertTrue($form->isSubmitted());
7172
$this->assertFalse($form->isValid());
72-
$this->assertEquals('The email must be a valid email address.', $form->getErrors(true)[0]->getMessage());
73+
74+
if (version_compare(Application::VERSION, '10', '>=')) {
75+
$this->assertEquals('The email field must be a valid email address.', $form->getErrors(true)[0]->getMessage());
76+
} else {
77+
$this->assertEquals('The email must be a valid email address.', $form->getErrors(true)[0]->getMessage());
78+
}
7379
}
7480

7581
public function testEmptyCollectionForm()
@@ -124,10 +130,19 @@ public function testInvalidCollectionForm()
124130
$this->assertTrue($form->isSubmitted());
125131
$this->assertFalse($form->isValid());
126132

127-
$this->assertEqualsCanonicalizing([
128-
'The children.1.email must be a valid email address.',
129-
'The emails.0 must be a valid email address.',
130-
], array_map(function($error) {
133+
if (version_compare(Application::VERSION, '10', '>=')) {
134+
$expected = [
135+
'The children.1.email field must be a valid email address.',
136+
'The emails.0 field must be a valid email address.',
137+
];
138+
} else {
139+
$expected = [
140+
'The children.1.email must be a valid email address.',
141+
'The emails.0 must be a valid email address.',
142+
];
143+
}
144+
145+
$this->assertEqualsCanonicalizing($expected, array_map(function($error) {
131146
return $error->getMessage();
132147
}, iterator_to_array($form->getErrors(true))));
133148
}

0 commit comments

Comments
 (0)